logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

This article applies to: ✔️ .NET Core 3.1 SDK and later versions

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 remove from the solution.   Unix/Linux  shell  globbing  pattern
         (https://en.wikipedia.org/wiki/Glob_(programming)) expansions are processed correctly by the dotnetsln
         command.

Description

       The dotnetsln command provides a convenient way to list and modify projects in a solution file.

   Createasolutionfile
       To  use the dotnetsln command, the solution file must already exist.  If you need to create one, use the
       dotnet new command with the sln template name.

       The following example creates a .sln file in the current folder, with the same name as the folder:

              dotnet new sln

       The following example creates a .sln file in the current folder, with the specified file name:

              dotnet new sln --name MySolution

       The following example creates a .sln file in the specified folder, with the same name as the folder:

              dotnet new sln --output MySolution

Dotnet Sln

Thisarticleappliesto: ✔️ .NET Core 3.1 SDK and later versions

Examples

       • List the projects in a solution:

                dotnet sln todo.sln list

       • Add a C# project to a solution:

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

       • Remove a C# project from a solution:

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

       • 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

       • Add multiple C# projects to a solution:

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

       • Remove multiple C# projects from a solution:

                dotnet sln todo.sln remove todo-app/todo-app.csproj back-end/back-end.csproj

       • Add multiple C# projects to a solution using a globbing pattern (Unix/Linux only):

                dotnet sln todo.sln add **/*.csproj

       • Add multiple C# projects to a solution using a globbing pattern (Windows PowerShell only):

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

       • Remove multiple C# projects from a solution using a globbing pattern (Unix/Linux only):

                dotnet sln todo.sln remove **/*.csproj

       • Remove multiple C# projects from a solution using a globbing pattern (Windows PowerShell only):

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

       • Create  a  solution, a console app, and two class libraries.  Add the projects to the solution, and use
         the --solution-folder option of dotnetsln to organize the class libraries into a solution folder.

                dotnet new sln -n mysolution
                dotnet new console -o myapp
                dotnet new classlib -o mylib1
                dotnet new classlib -o mylib2
                dotnet sln mysolution.sln add myapp\myapp.csproj
                dotnet sln mysolution.sln add mylib1\mylib1.csproj --solution-folder mylibs
                dotnet sln mysolution.sln add mylib2\mylib2.csproj --solution-folder mylibs

         The following screenshot shows the result in Visual Studio 2019 SolutionExplorer:

         :::image type=“content” source=“media/dotnet-sln/dotnet-sln-solution-folder.png” alt-text=“Solution Ex‐
         plorer showing class library projects grouped into a solution folder.”:::

Name

       dotnet-sln - Lists or modifies the projects in a .NET solution file.

Options

-?|-h|--help

         Prints out a description of how to use the command.

See Also

       • dotnet/sdk GitHub repo (https://github.com/dotnet/sdk) (.NET CLI source)

                                                   2024-10-02                                      dotnet-sln(1)

Synopsis

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

See Also