I'm a bit confused - the majority of .NET Core tutorials I have been reading have not mentioned "dotnet new sln" - they always just create the projects separately without any solution file to link them together.
Is "dotnet new sln" a new command?
When should I use this? What benefits do I gain from creating a .sln file instead of just having project files? Is it mainly for opening in Visual Studio? I use Visual Studio Code for Mac, so it may not be applicable.
I have googled "dotnet new sln" and the results are very minimal.
Description. The dotnet sln command provides a convenient way to list and modify projects in a solution file.
A file with . SLN extension represents a Visual Studio solution file that keeps information about the organization of projects in a solution file. The contents of such a solution file are written in plain text inside the file and can be observed/edited by opening the file in any text editor.
NET Core can be installed in two ways: By installing Visual Studio 2017/2019 or by installing . NET Core Runtime or SDK.
Visual Studio allows multiple projects in a solution. The data what projects are in a solution is in the sln (solution) file.
Is "dotnet new sln" a new command?
Yes. In version 1.0.1 of the dotnet command line interface, there is a dotnet new sln
command. The command came with the change from project.json to csproj. If we run dotnet new --help
, we will see "Solution File" as one of the templates.
> dotnet new --help Templates Short Name Language Tags ---------------------------------------------------------------------- Console Application console [C#], F# Common/Console Class library classlib [C#], F# Common/Library Unit Test Project mstest [C#], F# Test/MSTest xUnit Test Project xunit [C#], F# Test/xUnit ASP.NET Core Empty web [C#] Web/Empty ASP.NET Core Web App mvc [C#], F# Web/MVC ASP.NET Core Web API webapi [C#] Web/WebAPI Solution File sln Solution
when should I use this?
Two times to use a solution file are:
What benefits do I gain from creating a .sln file instead of just having project files? Is it mainly for opening in Visual Studio? I use Visual Studio Code for Mac, so it may not be applicable.
One of the benefits that do not require Visual Studio is the management of multiple projects as a single unit.
For instance, on a Mac with Visual Studio Code, we can use the dotnet
CLI to create a new solution, create a few projects, add those projects to the solution, restore the solution, and build the solution.
dotnet new sln --name FooBar dotnet new console --name Foo --output Foo dotnet new console --name Bar --output Bar dotnet sln add .\Foo\Foo.csproj dotnet sln add .\Bar\Bar.csproj dotnet restore dotnet build FooBar.sln
The last command, which calls dotnet build
, has the benefit of building all the projects that are in the solution. Without a solution, we would need to call dotnet build
on each project.
There are no doubt other benefits which do not require the use of Visual Studio. I leave those to you to discover.
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