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

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

问题描述

我有点困惑——我读过的大多数 .NET Core 教程都没有提到dotnet new sln"——它们总是单独创建项目,没有任何解决方案文件将它们链接在一起.

  1. dotnet new sln"是一个新命令吗?

  2. 我应该什么时候使用它?创建 .sln 文件而不是仅仅拥有项目文件对我有什么好处?主要是为了在 Visual Studio 中打开吗?我使用的是 Visual Studio Code for Mac,所以可能不适用.

我在谷歌上搜索了dotnet new sln",结果很少.

解决方案

dotnet new sln"是一个新命令吗?

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

>dotnet 新的 --help模板短名称语言标签----------------------------------------------------------------------控制台应用程序控制台 [C#]、F# 通用/控制台类库 classlib [C#], F# Common/Library单元测试项目 mstest [C#]、F# Test/MSTestxUnit 测试项目 xunit [C#], F# Test/xUnitASP.NET Core 空网页 [C#] 网页/空ASP.NET Core Web 应用 mvc [C#]、F# Web/MVCASP.NET Core Web API webapi [C#] Web/WebAPI解决方案文件 sln 解决方案

<块引用>

我应该什么时候使用它?

两次使用解决方案文件是:

  1. 当我们想要使用 Visual Studio 时,和/或
  2. 当我们希望将多个项目作为一个单元进行管理时.

<块引用>

创建 .sln 文件而不是仅仅拥有项目文件对我有什么好处?主要是为了在Visual Studio中打开吗?我使用的是 Visual Studio Code for Mac,所以可能不适用.

不需要 Visual Studio 的好处之一是将多个项目作为一个单元进行管理.

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

dotnet new sln --name FooBardotnet 新控制台 --name Foo --output Foodotnet 新控制台 --name Bar --output Bardotnet sln 添加 .FooFoo.csprojdotnet sln 添加 .BarBar.csprojdotnet 还原dotnet 构建 FooBar.sln

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

毫无疑问,还有其他不需要使用 Visual Studio 的好处.我把这些留给你去发现.

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.

解决方案

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 .FooFoo.csproj
dotnet sln add .BarBar.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.

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

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