.NET Core-何时使用“ dotnet new sln” [英] .NET Core - When to use "dotnet new sln"

查看:305
本文介绍了.NET Core-何时使用“ dotnet new sln”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点困惑-我读过的大多数.NET Core教程都没有提到 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. dotnet new sln是新命令吗?

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

何时我应该用这个吗?通过创建.sln文件而不是仅包含项目文件,我可以获得什么好处?它主要用于在Visual Studio中打开吗?我使用Mac的Visual Studio代码,因此可能不适用。

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.

我在Google上搜索了 dotnet new sln

I have googled "dotnet new sln" and the results are very minimal.

推荐答案


dotnet new sln是一个新命令吗? / p>

Is "dotnet new sln" a new command?

是。在dotnet命令行界面的1.0.1版本中,有一个 dotnet new sln 命令。该命令随从project.json更改为csproj 。如果我们运行 dotnet new --help ,我们将看到解决方案文件作为模板之一。

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. 当我们想使用Visual Studio时,和/或

  2. 当我们想使用Visual Studio时。将多个项目作为一个单元分开处理。




相反,创建.sln文件有什么好处?仅具有项目文件?它主要用于在Visual Studio中打开吗?我使用的是Visual Studio Code for Mac,因此可能不适用。

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.

不需要Visual Studio的好处之一是

One of the benefits that do not require Visual Studio is the management of multiple projects as a single unit.

例如,在带有Visual Studio Code的Mac上,我们可以使用 dotnet CLI创建一个新的解决方案,创建一些项目,将这些项目添加到解决方案中,还原该解决方案,然后构建该解决方案。

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

最后一个调用 dotnet build 的命令的好处是可以构建所有在解决方案中。没有解决方案,我们将需要在每个项目上调用 dotnet build

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.

毫无疑问,其他好处不需要使用Visual Studio。我把那些留给你去发现。

There are no doubt other benefits which do not require the use of Visual Studio. I leave those to you to discover.

这篇关于.NET Core-何时使用“ dotnet new sln”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆