Tip Of The Week

Tip of the Week: Creating a DotNet Core Solution file with multiple projects via the Command Line tools

Reading Time: 2 minutes

Today I’m going to outline the process and commands for creating a .net core solution file.  Then I’ll add multiple projects, with one of those projects referencing the other.  And I’ll do this all with the command line.

If you’re used to working with Visual Studio all this functionality is built into the IDE.  With a simple menu navigation of:  File -> New Project(s), a couple of Right Clicks (to set references) and a quick Save Solution, you’re all set up.

However if you’re using VS Code (which I occasionally do) then you need to go old school which means doing it all the command line way.  In general, it’s really easy to do, but figuring it out the first time (or remembering it after a couple of months) might take a few minutes.  Once it’s created you can easily transition between using VS Code and/or Visual Studio.  The great thing about having a solutions file: you can issue a “build” command against the entire solution.

Most of the documentation on Microsofts site (which I provided links below) are very helpful, however unless they’ve updated it recently, it doesn’t put all the pieces together.  Unfortunately, this means you’re stuck trying to figure it out by yourself.  So, in order to make it easy, I’ve pulled it all together and made a quick outline and step by step guide.

Let’s get started!

Microsoft References:

If you want to view the official documentation, the links are provided below.

Here are the steps:

  1. First create a Solution file.
  2. Then, create one or more Projects
  3. Next, add the Projects to the solution
  4. If you have projects that will reference another project, set Project references.
  5. Finally, run the Build command against the solution and make sure we have everything set up correctly.
dotnet new sln -n GeekProjects
dotnet new classlib -n DataModels
dotnet new console -n ConsoleApp

dotnet sln add DataModels
dotnet sln add ConsoleApp

cd ConsoleApp
dotnet add reference ../DataModels

cd ..
dotnet build

If all goes well you should have two projects for your solution and your output will look something like the screen shot below.

Until next time: Happy Coding