dotnet slndotnet sln

本文适用于: ✔️ .NET Core 2.x SDK 及更高版本This article applies to: ✔️ .NET Core 2.x SDK and later versions

“属性”Name

dotnet sln - 在 .NET Core 解决方案文件中列出或修改项目。dotnet sln - Lists or modifies the projects in a .NET Core solution file.

摘要Synopsis

dotnet sln [<SOLUTION_FILE>] [command]

dotnet sln [command] -h|--help

描述Description

使用 dotnet sln 命令,可以便捷地在解决方案文件中列出和修改项目。The dotnet sln command provides a convenient way to list and modify projects in a solution file.

若要使用 dotnet sln 命令,必须存在解决方案文件。To use the dotnet sln command, the solution file must already exist. 如果需要创建一个解决方案文件,请使用 dotnet new 命令,如下例所示:If you need to create one, use the dotnet new command, as in the following example:

dotnet new sln

自变量Arguments

  • SOLUTION_FILE

    要使用的解决方案文件。The solution file to use. 如果省略此参数,此命令会搜索当前目录来获取一个解决方案文件。If this argument is omitted, the command searches the current directory for one. 如果未找到解决方案文件或找到多个解决方案文件,则该命令将失败。If it finds no solution file or multiple solution files, the command fails.

选项Options

  • -h|--help

    打印出有关如何使用命令的说明。Prints out a description of how to use the command.

命令Commands

list

列出解决方案文件中的所有项目。Lists all projects in a solution file.

摘要Synopsis

dotnet sln list [-h|--help]

自变量Arguments

  • SOLUTION_FILE

    要使用的解决方案文件。The solution file to use. 如果省略此参数,此命令会搜索当前目录来获取一个解决方案文件。If this argument is omitted, the command searches the current directory for one. 如果未找到解决方案文件或找到多个解决方案文件,则该命令将失败。If it finds no solution file or multiple solution files, the command fails.

选项Options

  • -h|--help

    打印出有关如何使用命令的说明。Prints out a description of how to use the command.

add

将一个或多个项目添加到解决方案文件。Adds one or more projects to the solution file.

摘要Synopsis

dotnet sln [<SOLUTION_FILE>] add [--in-root] [-s|--solution-folder <PATH>] <PROJECT_PATH> [<PROJECT_PATH>...]
dotnet sln add [-h|--help]

自变量Arguments

  • SOLUTION_FILE

    要使用的解决方案文件。The solution file to use. 如果未指定,此命令会搜索当前目录以获取一个解决方案文件,如果找到多个解决方案文件,则该命令将失败。If it is unspecified, the command searches the current directory for one and fails if there are multiple solution files.

  • PROJECT_PATH

    要添加到解决方案的一个或多个项目的路径。The path to the project or projects to add to the solution. Unix/Linux shell glob 模式扩展由 dotnet sln 命令正确处理。Unix/Linux shell globbing pattern expansions are processed correctly by the dotnet sln command.

选项Options

  • -h|--help

    打印出有关如何使用命令的说明。Prints out a description of how to use the command.

  • --in-root

    将项目放在解决方案的根目录下,而不是创建解决方案文件夹。Places the projects in the root of the solution, rather than creating a solution folder. 自 .NET Core 3.0 SDK 起可用。Available since .NET Core 3.0 SDK.

  • -s|--solution-folder <PATH>

    要将项目添加到的目标解决方案文件夹路径。The destination solution folder path to add the projects to. 自 .NET Core 3.0 SDK 起可用。Available since .NET Core 3.0 SDK.

remove

从解决方案文件中删除一个或多个项目。Removes a project or multiple projects from the solution file.

摘要Synopsis

dotnet sln [<SOLUTION_FILE>] remove <PROJECT_PATH> [<PROJECT_PATH>...]
dotnet sln [<SOLUTION_FILE>] remove [-h|--help]

自变量Arguments

  • SOLUTION_FILE

    要使用的解决方案文件。The solution file to use. 如果保留未指定,此命令会搜索当前目录以获取一个解决方案文件,如果找到多个解决方案文件,则该命令将失败。If is left unspecified, the command searches the current directory for one and fails if there are multiple solution files.

  • PROJECT_PATH

    要添加到解决方案的一个或多个项目的路径。The path to the project or projects to add to the solution. Unix/Linux shell glob 模式扩展由 dotnet sln 命令正确处理。Unix/Linux shell globbing pattern expansions are processed correctly by the dotnet sln command.

选项Options

  • -h|--help

    打印出有关如何使用命令的说明。Prints out a description of how to use the command.

示例Examples

  • 在解决方案中列出项目:List the projects in a solution:

    dotnet sln todo.sln list
    
  • 将一个 C# 项目添加到解决方案中:Add a C# project to a solution:

    dotnet sln add todo-app/todo-app.csproj
    
  • 从解决方案中删除一个 C# 项目:Remove a C# project from a solution:

    dotnet sln remove todo-app/todo-app.csproj
    
  • 将多个 C# 项目添加到解决方案的根目录中:Add multiple C# projects to the root of a solution:

    dotnet sln todo.sln add todo-app/todo-app.csproj back-end/back-end.csproj --in-root
    
  • 将多个 C# 项目添加到解决方案中:Add multiple C# projects to a solution:

    dotnet sln todo.sln add todo-app/todo-app.csproj back-end/back-end.csproj
    
  • 从解决方案中删除多个 C# 项目:Remove multiple C# projects from a solution:

    dotnet sln todo.sln remove todo-app/todo-app.csproj back-end/back-end.csproj
    
  • 使用 glob 模式(仅限 Unix/Linux)将多个 C# 项目添加到解决方案中:Add multiple C# projects to a solution using a globbing pattern (Unix/Linux only):

    dotnet sln todo.sln add **/*.csproj
    
  • 使用 globbing 模式(仅限 Windows PowerShell)将多个 C# 项目添加到解决方案中:Add multiple C# projects to a solution using a globbing pattern (Windows PowerShell only):

    dotnet sln todo.sln add (ls -r **/*.csproj)
    
  • 使用 glob 模式(仅限 Unix/Linux)将多个 C# 项目从解决方案中删除:Remove multiple C# projects from a solution using a globbing pattern (Unix/Linux only):

    dotnet sln todo.sln remove **/*.csproj
    
  • 使用 globbing 模式(仅限 Windows PowerShell)将多个 C# 项目从解决方案中删除:Remove multiple C# projects from a solution using a globbing pattern (Windows PowerShell only):

    dotnet sln todo.sln remove (ls -r **/*.csproj)