Creating and editing solution files with DotNet Core on ubuntu

If you have worked with the .net framework for any length of time, you will be well acquainted with Solution Files, which contain the text-based information your development environment will used to load the name-value parameters of all the projects that comprise a software solution. 

Each project file will contain additional information read by the environment to populate the hierarchy of the specific project.

The information contained in a solution file is not only used by the IDE,  it is also used my MsBuild or any other build tool to build or compile the solution.

Do we need Solution files in VS Code ?

Although not strictly necessary from a pure development perspective, we don’t necessarily need solution files when developing with VS Code, but solution files do come in handy during the Build and Release phases of projects, so it is generally good practice to start thinking about using them in the early stages of your project development.

The latest release of the .net core framework, has seen a number of changes incorporated in regards to Development Project Management.  We’ve seen the demise of the project.json and the re-introduction of .csproj files.   We have also see the introduction the of creating Solution Files in the .net CLI


Creating a new solution file

It is now really easy to create solution file making use of dotnet new.

To create a new solution file in your current working directory :

This works great! However, typically you may want some additional control of the naming etc of your solution file. You can do this by making use of the command line arguments.

To get a full list of the available arguments simply use the help function

In order to create a new solution file with the name of SwcApi we simplay provide the name parameter

Your new solution file is now created and you can open and inspect the file in VS Code. Your Solution file is of no use until you start adding projects to it. so lets go ahead and some projects to it to start off.

Adding Projects to solution files

In my example I am going to add 2 new projects then I will add them to the Solution file. We’ll create an Web Api project and simple Class Library project.

We can now add these projects to our solution file using the dotnet sln [path-to-solution.sln] add [path-to-project.csproj]

You’ll see a confirmation message. You have npow successfully added projects to your solution file.

Removing projects from solution files

Removing projects files using the CLI is also fairly trivial process. Making use of the remove command i.e. dotnet sln remove [path-to-project.csproj]

List Projects

.NET CLI has the ability to list the projects in the solution file, instead of having to open it up and wade through the litany of GUIDs, which is especially handy when you working on a headless linux build server!

dotnet sln list


Making use of the .net core cli you can manage your solution files with ease, without having to edit the file by hand. It really is the worth the time and effort learning how to make use of the solution files, as it does drastically reduce the effort required in building your project later!

Additional References

Gary Woodfine

Freelance Full Stack Developer at
Helps businesses by improving their technical proficiencies and eliminating waste from the software development pipelines.

A unique background as business owner, marketing, software development and business development ensures that he can offer the optimum business consultancy services across a wide spectrum of business challenges.