Press "Enter" to skip to content

How To Start with src and tests Folders in your Solution File in VS2019

Organizing your code into src and tests folders on GitHub seems to be getting more and more popular. However, in Visual Studio 2019, it’s not very easy to accomplish. Here is how I do it.

Firstly, let me show you the final outcome:

Final Outcome of using src

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.