Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit aab9af7

Browse files
author
Peter Huene
committed
Implement uninstall tool command.
This commit implements the `uninstall tool` command. The `uninstall tool` command is responsible for uninstalling global tools that are installed with the `install tool` command. This commit heavily refactors the ToolPackage and ShellShim namespaces to better support the operations required for the uninstall command. Several string resources have been updated to be more informative or to correct oddly structured sentences. This commit also fixes `--version` on the install command not supporting ranges and wildcards. Fixes #8549. Issue #8485 is partially fixed by this commit (`--prerelease` is not yet implemented).
1 parent 787bee7 commit aab9af7

File tree

134 files changed

+6375
-3158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+6375
-3158
lines changed

src/Microsoft.DotNet.Cli.Utils/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ public static class Constants
2121

2222
public static readonly string ProjectArgumentName = "<PROJECT>";
2323
public static readonly string SolutionArgumentName = "<SLN_FILE>";
24+
public static readonly string ToolPackageArgumentName = "<PACKAGE_ID>";
2425
}
2526
}

src/Microsoft.DotNet.InternalAbstractions/DirectoryWrapper.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ public ITemporaryDirectory CreateTemporaryDirectory()
1919
return new TemporaryDirectory();
2020
}
2121

22-
public IEnumerable<string> GetFiles(string path, string searchPattern)
22+
public IEnumerable<string> EnumerateFileSystemEntries(string path)
2323
{
24-
return Directory.GetFiles(path, searchPattern);
24+
return Directory.EnumerateFileSystemEntries(path);
25+
}
26+
27+
public IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern)
28+
{
29+
return Directory.EnumerateFileSystemEntries(path, searchPattern);
2530
}
2631

2732
public string GetDirectoryFullName(string path)
@@ -52,5 +57,10 @@ public void Delete(string path, bool recursive)
5257
{
5358
Directory.Delete(path, recursive);
5459
}
60+
61+
public void Move(string source, string destination)
62+
{
63+
Directory.Move(source, destination);
64+
}
5565
}
5666
}

src/Microsoft.DotNet.InternalAbstractions/FileWrapper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public void WriteAllText(string path, string content)
4646
File.WriteAllText(path, content);
4747
}
4848

49+
public void Move(string source, string destination)
50+
{
51+
File.Move(source, destination);
52+
}
53+
4954
public void Delete(string path)
5055
{
5156
File.Delete(path);

src/Microsoft.DotNet.InternalAbstractions/IDirectory.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ internal interface IDirectory
1111

1212
ITemporaryDirectory CreateTemporaryDirectory();
1313

14-
IEnumerable<string> GetFiles(string path, string searchPattern);
14+
IEnumerable<string> EnumerateFileSystemEntries(string path);
15+
16+
IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern);
1517

1618
string GetDirectoryFullName(string path);
1719

1820
void CreateDirectory(string path);
1921

2022
void Delete(string path, bool recursive);
23+
24+
void Move(string source, string destination);
2125
}
2226
}

src/Microsoft.DotNet.InternalAbstractions/IFile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Stream OpenFile(
2525

2626
void WriteAllText(string path, string content);
2727

28+
void Move(string source, string destination);
29+
2830
void Delete(string path);
2931
}
3032
}

src/dotnet/BuiltInCommandsCatalog.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Microsoft.DotNet.Tools.Sln;
1919
using Microsoft.DotNet.Tools.Store;
2020
using Microsoft.DotNet.Tools.Test;
21+
using Microsoft.DotNet.Tools.Uninstall;
2122
using Microsoft.DotNet.Tools.VSTest;
2223
using System.Collections.Generic;
2324
using Microsoft.DotNet.Tools.Install;
@@ -149,6 +150,10 @@ public static class BuiltInCommandsCatalog
149150
{
150151
Command = InstallCommand.Run
151152
},
153+
["uninstall"] = new BuiltInCommandMetadata
154+
{
155+
Command = UninstallCommand.Run
156+
},
152157
["internal-reportinstallsuccess"] = new BuiltInCommandMetadata
153158
{
154159
Command = InternalReportinstallsuccess.Run

src/dotnet/CommonLocalizableStrings.resx

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,6 @@
520520
<data name="NoRestoreDescription" xml:space="preserve">
521521
<value>Does not do an implicit restore when executing the command.</value>
522522
</data>
523-
<data name="NuGetConfigurationFileDoesNotExist" xml:space="preserve">
524-
<value>NuGet configuration file {0} does not exist.</value>
525-
</data>
526523
<data name="ToolSettingsInvalidXml" xml:space="preserve">
527524
<value>Invalid XML: {0}</value>
528525
</data>
@@ -541,46 +538,77 @@
541538
<data name="ToolSettingsUnsupportedRunner" xml:space="preserve">
542539
<value>Command '{0}' uses unsupported runner '{1}'."</value>
543540
</data>
544-
<data name="EnvironmentPathLinuxManualInstruction" xml:space="preserve">
545-
<value>Cannot find the tools executable path. Please ensure {0} is added to your PATH.
546-
If you are using bash. You can do this by running the following command:
541+
<data name="ShellShimConflict" xml:space="preserve">
542+
<value>Command '{0}' conflicts with an existing command from another tool.</value>
543+
</data>
544+
<data name="CannotCreateShimForEmptyExecutablePath" xml:space="preserve">
545+
<value>Cannot create shell shim for an empty executable path.</value>
546+
</data>
547+
<data name="CannotCreateShimForEmptyCommand" xml:space="preserve">
548+
<value>Cannot create shell shim for an empty command.</value>
549+
</data>
550+
<data name="FailedToRetrieveToolConfiguration" xml:space="preserve">
551+
<value>Failed to retrieve tool configuration: {0}</value>
552+
</data>
553+
<data name="EnvironmentPathLinuxManualInstructions" xml:space="preserve">
554+
<value>Tools directory '{0}' is not currently on the PATH environment variable.
555+
If you are using bash, you can add it to your profile by running the following command:
547556

548-
cat &lt;&lt; EOF &gt;&gt; ~/.bash_profile
557+
cat &lt;&lt; \EOF &gt;&gt; ~/.bash_profile
549558
# Add .NET Core SDK tools
550-
export PATH="$PATH:{1}"
551-
EOF</value>
559+
export PATH="$PATH:{0}"
560+
EOF
561+
562+
You can add it to the current session by running the following command:
563+
564+
export PATH="$PATH:{0}"
565+
</value>
552566
</data>
553567
<data name="EnvironmentPathLinuxNeedLogout" xml:space="preserve">
554568
<value>Since you just installed the .NET Core SDK, you will need to logout or restart your session before running the tool you installed.</value>
555569
</data>
556-
<data name="EnvironmentPathOSXManualInstruction" xml:space="preserve">
557-
<value>Cannot find the tools executable path. Please ensure {0} is added to your PATH.
558-
If you are using bash, You can do this by running the following command:
570+
<data name="EnvironmentPathOSXManualInstructions" xml:space="preserve">
571+
<value>Tools directory '{0}' is not currently on the PATH environment variable.
572+
If you are using bash, you can add it to your profile by running the following command:
559573

560-
cat &lt;&lt; EOF &gt;&gt; ~/.bash_profile
574+
cat &lt;&lt; \EOF &gt;&gt; ~/.bash_profile
561575
# Add .NET Core SDK tools
562-
export PATH="$PATH:{1}"
563-
EOF</value>
576+
export PATH="$PATH:{0}"
577+
EOF
578+
579+
You can add it to the current session by running the following command:
580+
581+
export PATH="$PATH:{0}"
582+
</value>
564583
</data>
565584
<data name="EnvironmentPathOSXNeedReopen" xml:space="preserve">
566585
<value>Since you just installed the .NET Core SDK, you will need to reopen terminal before running the tool you installed.</value>
567586
</data>
568-
<data name="EnvironmentPathWindowsManualInstruction" xml:space="preserve">
569-
<value>Cannot find the tools executable path. Please ensure {0} is added to your PATH.
570-
You can do this by running the following command:
587+
<data name="EnvironmentPathWindowsManualInstructions" xml:space="preserve">
588+
<value>Tools directory '{0}' is not currently on the PATH environment variable.
589+
590+
You can add the directory to the PATH by running the following command:
571591

572-
setx PATH "%PATH%;{1}"</value>
592+
setx PATH "%PATH%;{0}"
593+
</value>
573594
</data>
574595
<data name="EnvironmentPathWindowsNeedReopen" xml:space="preserve">
575596
<value>Since you just installed the .NET Core SDK, you will need to reopen the Command Prompt window before running the tool you installed.</value>
576597
</data>
577-
<data name="FailInstallToolPermission" xml:space="preserve">
578-
<value>Failed to change permission:
579-
Error: {0}
580-
Output: {1}</value>
598+
<data name="FailedToCreateShellShim" xml:space="preserve">
599+
<value>Failed to create tool shim for command '{0}': {1}</value>
600+
</data>
601+
<data name="FailedToRemoveShellShim" xml:space="preserve">
602+
<value>Failed to remove tool shim for command '{0}': {1}</value>
603+
</data>
604+
<data name="FailedSettingShimPermissions" xml:space="preserve">
605+
<value>Failed to set user executable permissions for shell shim: {0}</value>
606+
</data>
607+
<data name="FailedToInstallToolPackage" xml:space="preserve">
608+
<value>Failed to install tool package '{0}': {1}</value>
581609
</data>
582-
<data name="FailInstallToolSameName" xml:space="preserve">
583-
<value>Failed to install tool {0}. A command with the same name already exists.</value>
610+
<data name="FailedToUninstallToolPackage" xml:space="preserve">
611+
<value>Failed to uninstall tool package '{0}': {1}</value>
584612
</data>
585613
<data name="ToolPackageMissingEntryPointFile" xml:space="preserve">
586614
<value>Package '{0}' is missing entry point file {1}.</value>
@@ -589,6 +617,6 @@ Output: {1}</value>
589617
<value>Package '{0}' is missing tool settings file DotnetToolSettings.xml.</value>
590618
</data>
591619
<data name="ToolPackageConflictPackageId" xml:space="preserve">
592-
<value>Tool '{0}' is already installed.</value>
620+
<value>Tool '{0}' (version '{1}') is already installed.</value>
593621
</data>
594622
</root>

src/dotnet/Parser.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ private static void ConfigureCommandLineLocalizedStrings()
5656
CompleteCommandParser.Complete(),
5757
InternalReportinstallsuccessCommandParser.InternalReportinstallsuccess(),
5858
InstallCommandParser.Install(),
59+
UninstallCommandParser.Uninstall(),
5960
CommonOptions.HelpOption(),
6061
Create.Option("--info", ""),
6162
Create.Option("-d", ""),

src/dotnet/ShellShim/CreateShimTransaction.cs

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/dotnet/ShellShim/DoNothingEnvironmentPath.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace Microsoft.DotNet.ShellShim
1111
{
12-
public class DoNothingEnvironmentPath : IEnvironmentPath
12+
internal class DoNothingEnvironmentPath : IEnvironmentPath
1313
{
1414
public void AddPackageExecutablePathToUserPath()
1515
{

0 commit comments

Comments
 (0)