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