How to add 'src' folder at solution root

I managed to do this, although it is a bit of a "cheat".

  1. Create Solution Folder called "src"

  2. In file explorer also create folder called "src" inside your solution folder

  3. Now when you add new project to the solution, add it to the "solution_folder\src" because "src" now exists on the disk. At this point, in the solution view, this project will be actually shown outside of the "src" folder.

  4. Simply drag that project to the "src" folder in your solution structure and you will have it under "src" folder in you solution view and in the actual "src" folder on the disk.

Note that "src" folder in the solution view is not the same "src" folder on the disk, one is solution folder and the other is the actual folder in file system, but your structure from solution view will follow structure in the file system.

I hope that this helps :)


You can use folder view option in solution explorer and create a src folder which is mapped to file drive and then create a projects under it.


So here is how I accomplish this in Visual Studio 2019. First here is the end result:

enter image description here

To get there requires some Command line. First open a Command window and change to your local root folder for your application. In my case it's C:\Code\NameOfCoolApp.

Once in the root folder of your application, type this in:

dotnet new sln

You should get something similar to The template "Solution File" was created successfully.

Next, we're going to stub out one of your projects in the solution, so use whatever your naming convention is here. In my case, we're going to stub out the Domain project. So from that same command window, type:

dotnet new classlib -o src/NameOfCoolApp.Domain

You should then see something like The template "Class Library" was created successfully and ending with Restore succeeded.

Next, I add a stubbed Unit Test:

dotnet new mstest -o tests/Domain.UnitTests

Following the successful message, we're then going to add the above two items to the Solution by starting with:

dotnet sln add src/NameOfCoolApp.Domain

And finally:

dotnet sln add tests/Domain.UnitTests

From here you should be able to open the Solution file with VS2019 and be good to move on with the rest of your project within Visual Studio.