1

I had a single csproj in my project in Visual Studio Code and wanted to rehouse it into a sub folder so that I could also have a test.csproj alongside so I created two new folders at the root:

root --api --test

And I used VSCode to move all the existing files into the new api folder so that I could have two csproj files separated out into two folders.

Everything went FUBAR, the only way I could fix it was to create a new project and copy all the files I needed across.

Is there currently a better way to do this without messing up all references to the existing csproj?

Steji
  • 580
  • 1
  • 6
  • 17
  • Possible duplicate of [Visual Studio move project to a different folder](https://stackoverflow.com/questions/2620027/visual-studio-move-project-to-a-different-folder) – baruchiro Mar 11 '19 at 05:43

1 Answers1

1

below is how we can create a solution and a console project in the same directory to simulate your situation

mkdir test
cd test 
dotnet new sln 
dotnet new console
dotnet sln add test.csproj

now you have a solution in test folder which it has a console type project named test.csproj

to relocate the console project to a sub directory :

dotnet sln remove test.csproj
mkdir console 
mv obj Program.cs test.csproj console/.
cd console

refactor all the references,namespaces and file names

rm -R obj
cd ..
dotnet sln add console/console.csproj

test:

dotnet run --project console/console.csproj

Hello World!

this is a practical way to relocate a project in dotnet core. P.S. the command are valid for Linux

Ali Alp
  • 691
  • 7
  • 10
  • I don't know if this is valid for Visual Studio Code, I thought VSCode projects were folder oriented rather than solution (sln) oriented? – Steji Mar 11 '19 at 15:42
  • In vsCode you can use the bash terminal for it – Ali Alp Mar 11 '19 at 15:56