Skip to content
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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 57 additions & 75 deletions docs/core/tools/dotnet-sln.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `dotnet sln remove` command removes one or more projects from a `.sln` (solution) file.
The `dotnet sln remove` command removes one or more projects from a solution file (`.sln` or `.slnx`).

This command updates the solution file but **does not delete** the project files from disk.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This command updates the solution file but **does not delete** the project files from disk.
The command updates the solution file but doesn't delete the project files.


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.
Copy link
Member

@baronfel baronfel Feb 13, 2025

Choose a reason for hiding this comment

The 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
The solution file to modify. If unspecified, the command searches for a `.sln` file in the current directory.
The solution file to modify. If unspecified, the command searches for a `.sln` or `.slnx` file in the current directory.

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.
Copy link
Member

@baronfel baronfel Feb 13, 2025

Choose a reason for hiding this comment

The 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
One or more paths to the project files (`.csproj` or `.vbproj`) that should be removed from the solution.
One or more paths to the project files to remove from the solution.

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.
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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 dotnet workload and its subcommands. That requires changes to the other sln subcommands and to the TOC. It would probably be best for you to address only the comments that are easy to do and leave the rest for us.

Did you have an opportunity to read the guidelines for contributions? The article begins with

We appreciate community contributions to documentation

But the first guideline is:

DON'T surprise us with large pull requests. Instead, file an issue and start a discussion so we can agree on a direction before you invest a large amount of time.


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)
Loading