如何使用 dotnet CLI(命令行)将项目(.csproj)添加到解决方案文件夹下的解决方案(.sln)?

How to add a Project (.csproj) to Solution (.sln) under a Solution Folder using dotnet CLI (command line)?

我正在尝试使用 dotnet sln 命令行将 csproj 添加到 sln。

使用以下命令可以轻松添加项目。

  dotnet sln todo.sln add todo-app/todo-app.csproj

但是如何在 Solution Folder

下添加相同的内容

请尝试使用以下代码将项目从项目子文件夹添加到解决方案

dotnet sln ../todo.sln add todo-app.csproj 

从 .NET Core 3 开始(预览,使用 3.0.100-preview7-X 测试)

dotnet sln solution.sln add --solution-folder foo1\foo2\foo3 bar.csproj

开始创建嵌套层次结构
solution.sln
|
└───foo1
│   │
│   └───foo2
│       │
│       └───foo3
│            │   bar
│            │   ...

按照以下步骤操作:

  1. dotnet new sln --name "your solution name"
  2. dotnet sln add "path of your .csproj file along with the name"

示例: 如果您的解决方案文件的名称是“MyProject.sln”并且 csproj 在同一路径中,则

  1. dotnet new sln --name MyProject.sln
  2. dotnet sln add MyProject.csproj