From 193a4ba730600ad26680f4a5e9265e4c95e6a03c Mon Sep 17 00:00:00 2001 From: Nilesh Sheth Date: Thu, 13 Feb 2025 19:56:02 +0530 Subject: [PATCH 1/6] Documented 'dotnet sln remove' command (#44877) --- docs/core/tools/dotnet-sln.md | 132 +++++++++++++++------------------- 1 file changed, 57 insertions(+), 75 deletions(-) diff --git a/docs/core/tools/dotnet-sln.md b/docs/core/tools/dotnet-sln.md index dac81d75ac341..c535fb532dd76 100644 --- a/docs/core/tools/dotnet-sln.md +++ b/docs/core/tools/dotnet-sln.md @@ -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 [] remove [...] dotnet sln [] 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. - 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. + 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. + 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. - 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) From 1e5e56703757c7e1ffbd2294a014cbc36e5e5b1f Mon Sep 17 00:00:00 2001 From: Nilesh Sheth Date: Sat, 22 Feb 2025 13:19:24 +0530 Subject: [PATCH 2/6] fix(docs): Correct default rollForward policy in global.json documentation --- docs/core/tools/global-json.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/tools/global-json.md b/docs/core/tools/global-json.md index 888c3f78b7038..12d1453060ae3 100644 --- a/docs/core/tools/global-json.md +++ b/docs/core/tools/global-json.md @@ -188,7 +188,7 @@ The following rules apply when determining which version of the SDK to use: - If a *global.json* file is found that doesn't specify an SDK version but it specifies an `allowPrerelease` value, the highest installed SDK version is used (equivalent to setting `rollForward` to `latestMajor`). Whether the latest SDK version can be release or prerelease depends on the value of `allowPrerelease`. `true` indicates prerelease versions are considered; `false` indicates that only release versions are considered. - If a *global.json* file is found and it specifies an SDK version: - - If no `rollForward` value is set, it uses `latestPatch` as the default `rollForward` policy. Otherwise, check each value and their behavior in the [rollForward](#rollforward) section. + - If no `rollForward` value is set, it uses `patch` as the default `rollForward` policy. Otherwise, check each value and their behavior in the [rollForward](#rollforward) section. - Whether prerelease versions are considered and what's the default behavior when `allowPrerelease` isn't set is described in the [allowPrerelease](#allowprerelease) section. ## Troubleshoot build warnings From 75291ca60092168867093afae0dec21b752683c6 Mon Sep 17 00:00:00 2001 From: Nilesh Sheth Date: Sat, 22 Feb 2025 13:23:53 +0530 Subject: [PATCH 3/6] fix(docs): Correct default rollForward policy in global.json documentation --- docs/core/tools/global-json.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/tools/global-json.md b/docs/core/tools/global-json.md index 12d1453060ae3..672f4c5d4c974 100644 --- a/docs/core/tools/global-json.md +++ b/docs/core/tools/global-json.md @@ -211,4 +211,4 @@ To avoid Visual Studio removing versions of the .NET SDK, install the stand-alon ## See also -- [How project SDKs are resolved](/visualstudio/msbuild/how-to-use-project-sdk#how-project-sdks-are-resolved) +- [How project SDKs are resolved](/visualstudio/msbuild/how-to-use-project-sdk#how-project-sdks-are-resolved) \ No newline at end of file From 375a6862c406a7d81a4a5e73deb8edde2c38610d Mon Sep 17 00:00:00 2001 From: Nilesh Sheth Date: Sat, 22 Feb 2025 13:26:11 +0530 Subject: [PATCH 4/6] fix(docs): Correct default rollForward policy in global.json documentation --- docs/core/tools/global-json.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/core/tools/global-json.md b/docs/core/tools/global-json.md index 672f4c5d4c974..888c3f78b7038 100644 --- a/docs/core/tools/global-json.md +++ b/docs/core/tools/global-json.md @@ -188,7 +188,7 @@ The following rules apply when determining which version of the SDK to use: - If a *global.json* file is found that doesn't specify an SDK version but it specifies an `allowPrerelease` value, the highest installed SDK version is used (equivalent to setting `rollForward` to `latestMajor`). Whether the latest SDK version can be release or prerelease depends on the value of `allowPrerelease`. `true` indicates prerelease versions are considered; `false` indicates that only release versions are considered. - If a *global.json* file is found and it specifies an SDK version: - - If no `rollForward` value is set, it uses `patch` as the default `rollForward` policy. Otherwise, check each value and their behavior in the [rollForward](#rollforward) section. + - If no `rollForward` value is set, it uses `latestPatch` as the default `rollForward` policy. Otherwise, check each value and their behavior in the [rollForward](#rollforward) section. - Whether prerelease versions are considered and what's the default behavior when `allowPrerelease` isn't set is described in the [allowPrerelease](#allowprerelease) section. ## Troubleshoot build warnings @@ -211,4 +211,4 @@ To avoid Visual Studio removing versions of the .NET SDK, install the stand-alon ## See also -- [How project SDKs are resolved](/visualstudio/msbuild/how-to-use-project-sdk#how-project-sdks-are-resolved) \ No newline at end of file +- [How project SDKs are resolved](/visualstudio/msbuild/how-to-use-project-sdk#how-project-sdks-are-resolved) From 2674ce2b9303bf8950b5593679591ccdcbc88988 Mon Sep 17 00:00:00 2001 From: Nilesh Sheth Date: Sat, 22 Feb 2025 13:27:46 +0530 Subject: [PATCH 5/6] fix(docs): Correct default rollForward policy in global.json documentation --- docs/core/tools/dotnet-sln.md | 132 +++++++++++++++++++--------------- 1 file changed, 75 insertions(+), 57 deletions(-) diff --git a/docs/core/tools/dotnet-sln.md b/docs/core/tools/dotnet-sln.md index c535fb532dd76..dac81d75ac341 100644 --- a/docs/core/tools/dotnet-sln.md +++ b/docs/core/tools/dotnet-sln.md @@ -122,7 +122,7 @@ dotnet sln add [-h|--help] ### `remove` -Removes one or more projects from the solution file. +Removes a project or multiple projects from the solution file. #### Synopsis @@ -131,80 +131,98 @@ dotnet sln [] remove [...] dotnet sln [] remove [-h|--help] ``` -#### 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. - #### Arguments -- **`SOLUTION_FILE`** - The solution file to modify. If unspecified, the command searches for a `.sln` file in the current directory. - If multiple solution files exist, an error is returned. +- **`SOLUTION_FILE`** + + 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. + +- **`PROJECT_PATH`** -- **`PROJECT_PATH`** - One or more paths to the project files (`.csproj` or `.vbproj`) that should be removed from the solution. - Unix/Linux shell [globbing patterns](https://en.wikipedia.org/wiki/Glob_(programming)) are supported. + 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. #### Options [!INCLUDE [help](../../../includes/cli-help.md)] ---- +## Examples -### **Examples** +- List the projects in a solution: -#### **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. -``` + ```dotnetcli + dotnet sln todo.sln list + ``` -#### **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. -``` +- Add a C# project to a solution: -#### **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. -``` + ```dotnetcli + dotnet sln add todo-app/todo-app.csproj + ``` -#### **Remove multiple projects using a globbing pattern (Unix/Linux only)** -```dotnetcli -dotnet sln todo.sln remove **/*.csproj -``` +- Remove a C# project from a solution: -#### **Remove multiple projects using a globbing pattern (Windows PowerShell only)** -```dotnetcli -dotnet sln todo.sln remove (ls -r **/*.csproj) -``` + ```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 + ``` -### **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. +- Add multiple C# projects to a solution: ---- + ```dotnetcli + dotnet sln todo.sln add todo-app/todo-app.csproj back-end/back-end.csproj + ``` -### **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/) -``` +- 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): + + ```dotnetcli + dotnet sln todo.sln add (ls -r **/*.csproj) + ``` + +- Remove multiple C# projects from a solution using a globbing pattern (Unix/Linux only): + + ```dotnetcli + dotnet sln todo.sln remove **/*.csproj + ``` + +- Remove multiple C# projects from a solution 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 + ``` + + 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/sdk GitHub repo](https://github.com/dotnet/sdk) (.NET CLI source) From 4d97ef1c62457103caf16ab685e6a30c1224402d Mon Sep 17 00:00:00 2001 From: Nilesh Sheth Date: Sat, 22 Feb 2025 13:33:46 +0530 Subject: [PATCH 6/6] fix(docs): Correct default rollForward policy in global.json documentation --- docs/core/tools/global-json.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/tools/global-json.md b/docs/core/tools/global-json.md index 888c3f78b7038..12d1453060ae3 100644 --- a/docs/core/tools/global-json.md +++ b/docs/core/tools/global-json.md @@ -188,7 +188,7 @@ The following rules apply when determining which version of the SDK to use: - If a *global.json* file is found that doesn't specify an SDK version but it specifies an `allowPrerelease` value, the highest installed SDK version is used (equivalent to setting `rollForward` to `latestMajor`). Whether the latest SDK version can be release or prerelease depends on the value of `allowPrerelease`. `true` indicates prerelease versions are considered; `false` indicates that only release versions are considered. - If a *global.json* file is found and it specifies an SDK version: - - If no `rollForward` value is set, it uses `latestPatch` as the default `rollForward` policy. Otherwise, check each value and their behavior in the [rollForward](#rollforward) section. + - If no `rollForward` value is set, it uses `patch` as the default `rollForward` policy. Otherwise, check each value and their behavior in the [rollForward](#rollforward) section. - Whether prerelease versions are considered and what's the default behavior when `allowPrerelease` isn't set is described in the [allowPrerelease](#allowprerelease) section. ## Troubleshoot build warnings