Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core - When to use "dotnet new sln"

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.

  1. Is "dotnet new sln" a new command?

  2. 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.

like image 399
AndyNZ Avatar asked Mar 11 '17 03:03

AndyNZ


People also ask

What is dotnet new SLN?

Description. The dotnet sln command provides a convenient way to list and modify projects in a solution file.

What is the use of .SLN file in asp net?

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.

Does .NET core need Visual Studio?

NET Core can be installed in two ways: By installing Visual Studio 2017/2019 or by installing . NET Core Runtime or SDK.

What does SLN mean in Visual Studio?

Visual Studio allows multiple projects in a solution. The data what projects are in a solution is in the sln (solution) file.


1 Answers

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:

  1. when we want to use Visual Studio, and/or
  2. when we want to manage several projects as a single unit.

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.

like image 176
Shaun Luttin Avatar answered Sep 25 '22 08:09

Shaun Luttin