Manpage logo

dotnet-sln - Lists or modifies the projects in a .NET solution file, or migrates the file to an f[I].slnxf[R] file.

dotnet sln  NAME  SYNOPSIS  DESCRIPTION  Create a solution file  ARGUMENTS  OPTIONS  Commands  list  SYNOPSIS  ARGUMENTS  OPTIONS  add  SYNOPSIS  ARGUMENTS  OPTIONS  remove  SYNOPSIS  ARGUMENTS  OPTIONS  migrate  SYNOPSIS  ARGUMENTS  OPTIONS  EXAMPLES  SEE ALSO 

dotnet sln

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

NAME

dotnet-sln - Lists or modifies the projects in a .NET solution file, or migrates the file to an .slnx file.

SYNOPSIS

dotnet sln [<SOLUTION_FILE>] [command]

dotnet sln [command] -h|--help

DESCRIPTION

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

Create a solution file

To use the dotnet sln 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 an .slnx file in the current folder, with the same name as the folder:

dotnet new sln

The following example creates an .slnx file in the current folder, with the specified file name:

dotnet new sln --name MySolution

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

dotnet new sln --output MySolution

In .NET 9 and earlier versions, dotnet new sln creates an .sln file instead of an .slnx file.

ARGUMENTS

SOLUTION_FILE

The solution file to use (either an .sln or .slnx file).

If unspecified, the command searches the current directory for an .sln or .slnx file and, if it finds exactly one, uses that file. If multiple solution files are found, the user is prompted to specify a file explicitly. If none are found, the command fails.

OPTIONS

-?|-h|--help

Prints out a description of how to use the command.

Commands

The following commands are available:

list

add

remove

migrate

list

Lists all projects in a solution file.

SYNOPSIS

dotnet sln list [-h|--help]

ARGUMENTS

SOLUTION_FILE

The solution file (.sln or .slnx file) or solution filter (.slnf file) to use.

If unspecified, the command searches the current directory for an .sln, .slnx, or .slnf file and, if it finds exactly one, uses that file. If multiple solution files or filters are found, the user is prompted to specify a file explicitly. If none are found, the command fails.

(Support for .slnf files was added in .NET SDK 9.0.3xx.)

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 (either an .sln or .slnx file).

If unspecified, the command searches the current directory for an .sln or .slnx file and, if it finds exactly one, uses that file. If multiple solution files are found, the user is prompted to specify a file explicitly. If none are found, the command fails.

PROJECT_PATH

The path to the project or projects to add to the solution. Unix/Linux shell globbing pattern (https://en.wikipedia.org/wiki/Glob_(programming)) expansions are processed correctly by the dotnet sln command.

If PROJECT_PATH includes folders that contain the project folder, that portion of the path is used to create solution folders. For example, the following commands create a solution with myapp in solution folder folder1/folder2:

dotnet new sln
dotnet new console --output folder1/folder2/myapp
dotnet sln add folder1/folder2/myapp

You can override this default behavior by using the --in-root or the -s|--solution-folder <PATH> option.

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. Can’t be used with -s|--solution-folder.

-s|--solution-folder <PATH>

The destination solution folder path to add the projects to. Can’t be used with --in-root.

remove

Removes a project or multiple projects from the solution file.

SYNOPSIS

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

ARGUMENTS

SOLUTION_FILE

The solution file to use (either an .sln or .slnx file).

If unspecified, the command searches the current directory for an .sln or .slnx file and, if it finds exactly one, uses that file. If multiple solution files are found, the user is prompted to specify a file explicitly. If none are found, the command fails.

PROJECT_PATH or PROJECT_NAME

The path to, or name of, 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 dotnet sln command.

If a project name is provided instead of a path, the project in the solution that matches the name, regardless of its path, is removed. If more than one matching project is found in the solution, the command errors out. Omit the project file extension in the name. (Support for removing projects by name was added in .NET 10.)

OPTIONS

-?|-h|--help

Prints out a description of how to use the command.

migrate

Generates an .slnx solution file from an .sln file.

SYNOPSIS

dotnet sln [<SOLUTION_FILE>] migrate
dotnet sln [<SOLUTION_FILE>] migrate [-h|--help]

ARGUMENTS

SOLUTION_FILE

The .sln solution file to migrate.

If unspecified, the command searches the current directory for an .sln file and, if it finds exactly one, uses that file. If multiple .sln files are found, the user is prompted to specify a file explicitly. If none are found, the command fails.

If you specify an .slnx file instead of an .sln file, or if an .slnx file with the same file name (minus the .sln extension) already exists in the directory, the command fails.

OPTIONS

-?|-h|--help

Prints out a description of how to use the command.

EXAMPLES

List the projects in a solution:

dotnet sln todo.slnx 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.slnx add todo-app/todo-app.csproj back-end/back-end.csproj --in-root

Add multiple C# projects to a solution:

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

Remove multiple C# projects from a solution:

dotnet sln todo.slnx 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.slnx add **/*.csproj

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

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

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

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

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

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

Generate an .slnx file from a .sln file:

dotnet sln todo.sln migrate

Create a solution, a console app, and two class libraries. Add the projects to the solution, and use the --solution-folder option of dotnet sln 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.slnx add myapp\myapp.csproj
dotnet sln mysolution.slnx add mylib1\mylib1.csproj --solution-folder mylibs
dotnet sln mysolution.slnx add mylib2\mylib2.csproj --solution-folder mylibs

The following screenshot shows the result in Visual Studio 2019 Solution Explorer:

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

SEE ALSO

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


Updated 2026-06-01 - jenkler.se | uex.se