This is going to sound like a silly question, but Visual Studio does not seem to let me do this simple organization which I see all the time on github.
I start with new empty solution.
I then want to add a "src" folder which will contain project multiple projects. If I right click and select "Add Folder" VS adds a virtual folder, not an actual folder.
If I use Windows Explorer to create a new folder in the desired location, VS ignores it and does not let me "Add to solution"
If I add a project, it adds the project at the root, not in the desired folder.
So, how do I add this folder?
Creating Solution Folders To create a folder within the solution, right-click the solution name in the Solution Explorer pane and choose "Add", then "New Solution Folder" from the context-sensitive menu. To create a subfolder, start by right-clicking an existing solution folder and then choose the same menu options.
The src stands for source. The /src folder comprises of the raw non-minified code. The /src folder is used to store the file with the primary purpose of reading (and/or editing) the code. The /src folder contains all the sources, i.e. the code which is required to be manipulated before it can be used.
I managed to do this, although it is a bit of a "cheat".
Create Solution Folder called "src"
In file explorer also create folder called "src" inside your solution folder
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.
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 :)
So here is how I accomplish this in Visual Studio 2019. First here is the end result:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With