-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dotnet sln remove command (#44877) #44884
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -122,7 +122,7 @@ dotnet sln add [-h|--help] | |||||
|
||||||
### `remove` | ||||||
|
||||||
Removes a project or multiple projects from the solution file. | ||||||
Removes one or more projects from the solution file. | ||||||
|
||||||
#### Synopsis | ||||||
|
||||||
|
@@ -131,98 +131,80 @@ dotnet sln [<SOLUTION_FILE>] remove <PROJECT_PATH> [<PROJECT_PATH>...] | |||||
dotnet sln [<SOLUTION_FILE>] remove [-h|--help] | ||||||
``` | ||||||
|
||||||
#### Arguments | ||||||
|
||||||
- **`SOLUTION_FILE`** | ||||||
#### Description | ||||||
The `dotnet sln remove` command removes one or more projects from a `.sln` (solution) file. | ||||||
This command updates the solution file but **does not delete** the project files from disk. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
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. | ||||||
#### Arguments | ||||||
|
||||||
- **`PROJECT_PATH`** | ||||||
- **`SOLUTION_FILE`** | ||||||
The solution file to modify. If unspecified, the command searches for a `.sln` file in the current directory. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As of 9.0.200, this isn't strictly true anymore - slnx files will be considered as well if they are present in the current directory.
Suggested change
|
||||||
If multiple solution files exist, an error is returned. | ||||||
|
||||||
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 `dotnet sln` command. | ||||||
- **`PROJECT_PATH`** | ||||||
One or more paths to the project files (`.csproj` or `.vbproj`) that should be removed from the solution. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The command supports many more types of project files than just csproj or vbproj - I think the clarification here could be removed entirely.
Suggested change
|
||||||
Unix/Linux shell [globbing patterns](https://en.wikipedia.org/wiki/Glob_(programming)) are supported. | ||||||
|
||||||
#### Options | ||||||
|
||||||
[!INCLUDE [help](../../../includes/cli-help.md)] | ||||||
|
||||||
## Examples | ||||||
|
||||||
- List the projects in a solution: | ||||||
|
||||||
```dotnetcli | ||||||
dotnet sln todo.sln list | ||||||
``` | ||||||
|
||||||
- Add a C# project to a solution: | ||||||
|
||||||
```dotnetcli | ||||||
dotnet sln add todo-app/todo-app.csproj | ||||||
``` | ||||||
|
||||||
- Remove a C# project from a solution: | ||||||
|
||||||
```dotnetcli | ||||||
dotnet sln remove todo-app/todo-app.csproj | ||||||
``` | ||||||
|
||||||
- Add multiple C# projects to the root of a solution: | ||||||
|
||||||
```dotnetcli | ||||||
dotnet sln todo.sln add todo-app/todo-app.csproj back-end/back-end.csproj --in-root | ||||||
``` | ||||||
|
||||||
- Add multiple C# projects to a solution: | ||||||
|
||||||
```dotnetcli | ||||||
dotnet sln todo.sln add todo-app/todo-app.csproj back-end/back-end.csproj | ||||||
``` | ||||||
|
||||||
- Remove multiple C# projects from a solution: | ||||||
|
||||||
```dotnetcli | ||||||
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): | ||||||
|
||||||
```dotnetcli | ||||||
dotnet sln todo.sln add **/*.csproj | ||||||
``` | ||||||
--- | ||||||
|
||||||
- Add multiple C# projects to a solution using a globbing pattern (Windows PowerShell only): | ||||||
### **Examples** | ||||||
|
||||||
```dotnetcli | ||||||
dotnet sln todo.sln add (ls -r **/*.csproj) | ||||||
``` | ||||||
#### **Remove a single project from a solution** | ||||||
```dotnetcli | ||||||
dotnet sln todo.sln remove todo-app/todo-app.csproj | ||||||
``` | ||||||
**Expected Output:** | ||||||
``` | ||||||
Removed project(s) from solution file. | ||||||
``` | ||||||
|
||||||
- Remove multiple C# projects from a solution using a globbing pattern (Unix/Linux only): | ||||||
#### **Remove multiple projects from a solution** | ||||||
```dotnetcli | ||||||
dotnet sln todo.sln remove todo-app/todo-app.csproj back-end/back-end.csproj | ||||||
``` | ||||||
**Expected Output:** | ||||||
``` | ||||||
Removed project(s) from solution file. | ||||||
``` | ||||||
|
||||||
```dotnetcli | ||||||
dotnet sln todo.sln remove **/*.csproj | ||||||
``` | ||||||
#### **Remove a project when a solution file is automatically detected** | ||||||
```dotnetcli | ||||||
dotnet sln remove todo-app/todo-app.csproj | ||||||
``` | ||||||
**Expected Output:** | ||||||
``` | ||||||
Removed project(s) from solution file. | ||||||
``` | ||||||
|
||||||
- Remove multiple C# projects from a solution using a globbing pattern (Windows PowerShell only): | ||||||
#### **Remove multiple projects using a globbing pattern (Unix/Linux only)** | ||||||
```dotnetcli | ||||||
dotnet sln todo.sln remove **/*.csproj | ||||||
``` | ||||||
|
||||||
```dotnetcli | ||||||
dotnet sln todo.sln remove (ls -r **/*.csproj) | ||||||
``` | ||||||
#### **Remove multiple projects using a globbing pattern (Windows PowerShell only)** | ||||||
```dotnetcli | ||||||
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 `dotnet sln` to organize the class libraries into a solution folder. | ||||||
--- | ||||||
|
||||||
```dotnetcli | ||||||
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 | ||||||
``` | ||||||
### **Notes** | ||||||
- If the solution file **does not exist**, the command will fail with an error. | ||||||
- If a specified project is **not part of the solution**, the command will display a message but continue execution. | ||||||
- **This command does not delete** the project files from disk; it only removes them from the solution file. | ||||||
- If a solution file is not explicitly provided, `dotnet sln remove` will attempt to find one in the current directory. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add note here to explain the sln vs slnx probing algorithm that I described in the linked issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency in the CLI documentation, these kinds of notes should go in a Description section near the top of the file, following the synopsis. Changes for formatting consistency are also needed in the examples section. The article also needs to be split into multiple files (one for each subcommand) to be consistent with what was done for Did you have an opportunity to read the guidelines for contributions? The article begins with
But the first guideline is:
|
||||||
|
||||||
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 sln`](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-sln) | ||||||
- [`dotnet sln add`](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-sln#add) | ||||||
- [Working with .NET CLI](https://learn.microsoft.com/en-us/dotnet/core/tools/) | ||||||
``` | ||||||
|
||||||
## See also | ||||||
|
||||||
- [dotnet/sdk GitHub repo](https://github.com/dotnet/sdk) (.NET CLI source) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.