1dotnet-sln(1) .NET Documentation dotnet-sln(1)
2
3
4
6 This article applies to: ✔️ .NET Core 3.1 SDK and later versions
7
9 dotnet-sln - Lists or modifies the projects in a .NET solution file.
10
12 dotnet sln [<SOLUTION_FILE>] [command]
13
14 dotnet sln [command] -h|--help
15
17 The dotnet sln command provides a convenient way to list and modify
18 projects in a solution file.
19
20 Create a solution file
21 To use the dotnet sln command, the solution file must already exist.
22 If you need to create one, use the dotnet new command with the sln tem‐
23 plate name.
24
25 The following example creates a .sln file in the current folder, with
26 the same name as the folder:
27
28 dotnet new sln
29
30 The following example creates a .sln file in the current folder, with
31 the specified file name:
32
33 dotnet new sln --name MySolution
34
35 The following example creates a .sln file in the specified folder, with
36 the same name as the folder:
37
38 dotnet new sln --output MySolution
39
41 • SOLUTION_FILE
42
43 The solution file to use. If this argument is omitted, the command
44 searches the current directory for one. If it finds no solution file
45 or multiple solution files, the command fails.
46
48 • -?|-h|--help
49
50 Prints out a description of how to use the command.
51
52 Commands
53 list
54 Lists all projects in a solution file.
55
57 dotnet sln list [-h|--help]
58
60 • SOLUTION_FILE
61
62 The solution file to use. If this argument is omitted, the command
63 searches the current directory for one. If it finds no solution file
64 or multiple solution files, the command fails.
65
67 • -?|-h|--help
68
69 Prints out a description of how to use the command.
70
71 add
72 Adds one or more projects to the solution file.
73
75 dotnet sln [<SOLUTION_FILE>] add [--in-root] [-s|--solution-folder <PATH>] <PROJECT_PATH> [<PROJECT_PATH>...]
76 dotnet sln add [-h|--help]
77
79 • SOLUTION_FILE
80
81 The solution file to use. If it is unspecified, the command searches
82 the current directory for one and fails if there are multiple solu‐
83 tion files.
84
85 • PROJECT_PATH
86
87 The path to the project or projects to add to the solution.
88 Unix/Linux shell globbing pattern (https://en.wikipedia.org/wi‐
89 ki/Glob_(programming)) expansions are processed correctly by the dot‐
90 net sln command.
91
92 If PROJECT_PATH includes folders that contain the project folder,
93 that portion of the path is used to create solution folders. For ex‐
94 ample, the following commands create a solution with myapp in solu‐
95 tion folder folder1/folder2:
96
97 dotnet new sln
98 dotnet new console --output folder1/folder2/myapp
99 dotnet sln add folder1/folder2/myapp
100
101 You can override this default behavior by using the --in-root or the
102 -s|--solution-folder <PATH> option.
103
105 • -?|-h|--help
106
107 Prints out a description of how to use the command.
108
109 • --in-root
110
111 Places the projects in the root of the solution, rather than creating
112 a solution folder. Can’t be used with -s|--solution-folder.
113
114 • -s|--solution-folder <PATH>
115
116 The destination solution folder path to add the projects to. Can’t
117 be used with --in-root.
118
119 remove
120 Removes a project or multiple projects from the solution file.
121
123 dotnet sln [<SOLUTION_FILE>] remove <PROJECT_PATH> [<PROJECT_PATH>...]
124 dotnet sln [<SOLUTION_FILE>] remove [-h|--help]
125
127 • SOLUTION_FILE
128
129 The solution file to use. If it is unspecified, the command searches
130 the current directory for one and fails if there are multiple solu‐
131 tion files.
132
133 • PROJECT_PATH
134
135 The path to the project or projects to remove from the solution.
136 Unix/Linux shell globbing pattern (https://en.wikipedia.org/wi‐
137 ki/Glob_(programming)) expansions are processed correctly by the dot‐
138 net sln command.
139
141 • -?|-h|--help
142
143 Prints out a description of how to use the command.
144
146 • List the projects in a solution:
147
148 dotnet sln todo.sln list
149
150 • Add a C# project to a solution:
151
152 dotnet sln add todo-app/todo-app.csproj
153
154 • Remove a C# project from a solution:
155
156 dotnet sln remove todo-app/todo-app.csproj
157
158 • Add multiple C# projects to the root of a solution:
159
160 dotnet sln todo.sln add todo-app/todo-app.csproj back-end/back-end.csproj --in-root
161
162 • Add multiple C# projects to a solution:
163
164 dotnet sln todo.sln add todo-app/todo-app.csproj back-end/back-end.csproj
165
166 • Remove multiple C# projects from a solution:
167
168 dotnet sln todo.sln remove todo-app/todo-app.csproj back-end/back-end.csproj
169
170 • Add multiple C# projects to a solution using a globbing pattern
171 (Unix/Linux only):
172
173 dotnet sln todo.sln add **/*.csproj
174
175 • Add multiple C# projects to a solution using a globbing pattern (Win‐
176 dows PowerShell only):
177
178 dotnet sln todo.sln add (ls -r **/*.csproj)
179
180 • Remove multiple C# projects from a solution using a globbing pattern
181 (Unix/Linux only):
182
183 dotnet sln todo.sln remove **/*.csproj
184
185 • Remove multiple C# projects from a solution using a globbing pattern
186 (Windows PowerShell only):
187
188 dotnet sln todo.sln remove (ls -r **/*.csproj)
189
190 • Create a solution, a console app, and two class libraries. Add the
191 projects to the solution, and use the --solution-folder option of
192 dotnet sln to organize the class libraries into a solution folder.
193
194 dotnet new sln -n mysolution
195 dotnet new console -o myapp
196 dotnet new classlib -o mylib1
197 dotnet new classlib -o mylib2
198 dotnet sln mysolution.sln add myapp\myapp.csproj
199 dotnet sln mysolution.sln add mylib1\mylib1.csproj --solution-folder mylibs
200 dotnet sln mysolution.sln add mylib2\mylib2.csproj --solution-folder mylibs
201
202 The following screenshot shows the result in Visual Studio 2019 Solu‐
203 tion Explorer:
204
205 :::image type=“content” source=“media/dotnet-sln/dotnet-sln-solution-
206 folder.png” alt-text=“Solution Explorer showing class library
207 projects grouped into a solution folder.”:::
208
210 • dotnet/sdk GitHub repo (https://github.com/dotnet/sdk) (.NET CLI
211 source)
212
213
214
215 2022-10-10 dotnet-sln(1)