Skip to content

Commit 9772abc

Browse files
authored
Updates for .slnx files (#45003)
1 parent dc0f173 commit 9772abc

File tree

1 file changed

+63
-17
lines changed

1 file changed

+63
-17
lines changed

docs/core/tools/dotnet-sln.md

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
22
title: dotnet sln command
33
description: The dotnet-sln command provides a convenient option to add, remove, and list projects in a solution file.
4-
ms.date: 05/18/2022
4+
ms.date: 02/24/2025
55
---
66
# dotnet sln
77

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

1010
## Name
1111

12-
`dotnet sln` - Lists or modifies the projects in a .NET solution file.
12+
`dotnet sln` - Lists or modifies the projects in a .NET solution file, or migrates the file to an *.slnx* file.
1313

1414
## Synopsis
1515

@@ -49,14 +49,23 @@ dotnet new sln --output MySolution
4949

5050
- **`SOLUTION_FILE`**
5151

52-
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.
52+
The solution file to use (either an *.sln* or *.slnx* file).
53+
54+
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.
5355

5456
## Options
5557

5658
[!INCLUDE [help](../../../includes/cli-help.md)]
5759

5860
## Commands
5961

62+
The following commands are available:
63+
64+
- [`list`](#list)
65+
- [`add`](#add)
66+
- [`remove`](#remove)
67+
- [`migrate`](#migrate)
68+
6069
### `list`
6170

6271
Lists all projects in a solution file.
@@ -71,7 +80,9 @@ dotnet sln list [-h|--help]
7180

7281
- **`SOLUTION_FILE`**
7382

74-
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.
83+
The solution file to use (either an *.sln* or *.slnx* file).
84+
85+
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.
7586

7687
#### Options
7788

@@ -92,7 +103,9 @@ dotnet sln add [-h|--help]
92103

93104
- **`SOLUTION_FILE`**
94105

95-
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.
106+
The solution file to use (either an *.sln* or *.slnx* file).
107+
108+
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.
96109

97110
- **`PROJECT_PATH`**
98111

@@ -135,7 +148,9 @@ dotnet sln [<SOLUTION_FILE>] remove [-h|--help]
135148

136149
- **`SOLUTION_FILE`**
137150

138-
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.
151+
The solution file to use (either an *.sln* or *.slnx* file).
152+
153+
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.
139154

140155
- **`PROJECT_PATH`**
141156

@@ -145,12 +160,37 @@ dotnet sln [<SOLUTION_FILE>] remove [-h|--help]
145160

146161
[!INCLUDE [help](../../../includes/cli-help.md)]
147162

163+
### `migrate`
164+
165+
Generates an *.slnx* solution file from an *.sln* file.
166+
167+
#### Synopsis
168+
169+
```dotnetcli
170+
dotnet sln [<SOLUTION_FILE>] migrate
171+
dotnet sln [<SOLUTION_FILE>] migrate [-h|--help]
172+
```
173+
174+
#### Arguments
175+
176+
- **`SOLUTION_FILE`**
177+
178+
The *.sln* solution file to migrate.
179+
180+
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.
181+
182+
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.
183+
184+
#### Options
185+
186+
[!INCLUDE [help](../../../includes/cli-help.md)]
187+
148188
## Examples
149189

150190
- List the projects in a solution:
151191

152192
```dotnetcli
153-
dotnet sln todo.sln list
193+
dotnet sln todo.slnx list
154194
```
155195

156196
- Add a C# project to a solution:
@@ -168,43 +208,49 @@ dotnet sln [<SOLUTION_FILE>] remove [-h|--help]
168208
- Add multiple C# projects to the root of a solution:
169209

170210
```dotnetcli
171-
dotnet sln todo.sln add todo-app/todo-app.csproj back-end/back-end.csproj --in-root
211+
dotnet sln todo.slnx add todo-app/todo-app.csproj back-end/back-end.csproj --in-root
172212
```
173213

174214
- Add multiple C# projects to a solution:
175215

176216
```dotnetcli
177-
dotnet sln todo.sln add todo-app/todo-app.csproj back-end/back-end.csproj
217+
dotnet sln todo.slnx add todo-app/todo-app.csproj back-end/back-end.csproj
178218
```
179219

180220
- Remove multiple C# projects from a solution:
181221

182222
```dotnetcli
183-
dotnet sln todo.sln remove todo-app/todo-app.csproj back-end/back-end.csproj
223+
dotnet sln todo.slnx remove todo-app/todo-app.csproj back-end/back-end.csproj
184224
```
185225

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

188228
```dotnetcli
189-
dotnet sln todo.sln add **/*.csproj
229+
dotnet sln todo.slnx add **/*.csproj
190230
```
191231

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

194234
```dotnetcli
195-
dotnet sln todo.sln add (ls -r **/*.csproj)
235+
dotnet sln todo.slnx add (ls -r **/*.csproj)
196236
```
197237

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

200240
```dotnetcli
201-
dotnet sln todo.sln remove **/*.csproj
241+
dotnet sln todo.slnx remove **/*.csproj
202242
```
203243

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

206246
```dotnetcli
207-
dotnet sln todo.sln remove (ls -r **/*.csproj)
247+
dotnet sln todo.slnx remove (ls -r **/*.csproj)
248+
```
249+
250+
- Generate an *.slnx* file from a *.sln* file:
251+
252+
```dotnetcli
253+
dotnet sln todo.sln migrate
208254
```
209255

210256
- 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.
@@ -214,9 +260,9 @@ dotnet sln [<SOLUTION_FILE>] remove [-h|--help]
214260
dotnet new console -o myapp
215261
dotnet new classlib -o mylib1
216262
dotnet new classlib -o mylib2
217-
dotnet sln mysolution.sln add myapp\myapp.csproj
218-
dotnet sln mysolution.sln add mylib1\mylib1.csproj --solution-folder mylibs
219-
dotnet sln mysolution.sln add mylib2\mylib2.csproj --solution-folder mylibs
263+
dotnet sln mysolution.slnx add myapp\myapp.csproj
264+
dotnet sln mysolution.slnx add mylib1\mylib1.csproj --solution-folder mylibs
265+
dotnet sln mysolution.slnx add mylib2\mylib2.csproj --solution-folder mylibs
220266
```
221267

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

0 commit comments

Comments
 (0)