From 71777a1606e63fb07103c4b82ce1e88403e3859e Mon Sep 17 00:00:00 2001 From: Eduardo Villalpando Mello Date: Wed, 16 Apr 2025 16:43:37 -0700 Subject: [PATCH 1/8] Remove LocalizableStrings.Designer.cs --- .../LocalizableStrings.Designer.cs | 72 ------------------- 1 file changed, 72 deletions(-) delete mode 100644 src/dotnet-bootstrapper/LocalizableStrings.Designer.cs diff --git a/src/dotnet-bootstrapper/LocalizableStrings.Designer.cs b/src/dotnet-bootstrapper/LocalizableStrings.Designer.cs deleted file mode 100644 index 8ff3e4a7..00000000 --- a/src/dotnet-bootstrapper/LocalizableStrings.Designer.cs +++ /dev/null @@ -1,72 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Microsoft.DotNet.Tools.Uninstall -{ - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class LocalizableStrings - { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal LocalizableStrings() - { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if (object.ReferenceEquals(resourceMan, null)) - { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.DotNet.Tools.Uninstall.LocalizableStrings", typeof(LocalizableStrings).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { - return resourceCulture; - } - set - { - resourceCulture = value; - } - } - } -} From 8c10e2dfea2a9572ca96ab16092bb399f0fee179 Mon Sep 17 00:00:00 2001 From: Eduardo Villalpando Mello Date: Wed, 16 Apr 2025 17:07:41 -0700 Subject: [PATCH 2/8] Use System.CommandLine --- src/dotnet-bootstrapper/Program.cs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/dotnet-bootstrapper/Program.cs b/src/dotnet-bootstrapper/Program.cs index e04cb49d..04144fa5 100644 --- a/src/dotnet-bootstrapper/Program.cs +++ b/src/dotnet-bootstrapper/Program.cs @@ -1,13 +1,30 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -namespace Microsoft.DotNet.Tools.Bootstrapper +using System.CommandLine; +using System.CommandLine.Builder; +using System.CommandLine.Parsing; +using System.IO; +using System.Threading.Tasks; +namespace Microsoft.DotNet.Tools.Bootstrapper; + +class Program { - internal class Program + static int Main(string[] args) { - internal static int Main(string[] args) + var rootCommand = new RootCommand("dotnet bootstrapper"); + + var installCommand = new Command("install", "Install the specified version of the .NET SDK.") { - return 0; - } + new Argument("version") + { + Description = "The version of the .NET SDK to install.", + Arity = ArgumentArity.ExactlyOne + } + }; + + rootCommand.AddCommand(installCommand); + + return rootCommand.Invoke(args); } } From ec9633622ac3bcd5289f4c07ace302ebbdee1b64 Mon Sep 17 00:00:00 2001 From: Forgind <12969783+Forgind@users.noreply.github.com> Date: Mon, 21 Apr 2025 13:37:36 -0700 Subject: [PATCH 3/8] Add real command parser --- .../BootstrapperCommandParser.cs | 50 +++++++++++++++++++ src/dotnet-bootstrapper/Program.cs | 15 +----- .../EndToEndTests.cs | 3 +- 3 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 src/dotnet-bootstrapper/BootstrapperCommandParser.cs diff --git a/src/dotnet-bootstrapper/BootstrapperCommandParser.cs b/src/dotnet-bootstrapper/BootstrapperCommandParser.cs new file mode 100644 index 00000000..e754a6ae --- /dev/null +++ b/src/dotnet-bootstrapper/BootstrapperCommandParser.cs @@ -0,0 +1,50 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.CommandLine; +using System.CommandLine.Builder; +using System.CommandLine.Invocation; +using System.CommandLine.Parsing; +using System.Reflection; + +namespace Microsoft.DotNet.Tools.Bootstrapper +{ + internal static class BootstrapperCommandParser + { + public static Parser BootstrapParser; + + public static RootCommand BootstrapperRootCommand = new RootCommand("dotnet bootstrapper"); + + public static readonly Command VersionCommand = new Command("--version"); + + private static readonly Lazy _assemblyVersion = + new Lazy(() => + { + var assembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly(); + var assemblyVersionAttribute = assembly.GetCustomAttribute(); + if (assemblyVersionAttribute == null) + { + return assembly.GetName().Version.ToString(); + } + else + { + return assemblyVersionAttribute.InformationalVersion; + } + }); + + static BootstrapperCommandParser() + { + BootstrapperRootCommand.AddCommand(VersionCommand); + VersionCommand.Handler = CommandHandler.Create(() => + { + Console.WriteLine(_assemblyVersion.Value); + }); + + BootstrapParser = new CommandLineBuilder(BootstrapperRootCommand) + .UseDefaults() + // .UseHelpBuilder(context => new UninstallHelpBuilder(context.Console)) + .Build(); + } + } +} diff --git a/src/dotnet-bootstrapper/Program.cs b/src/dotnet-bootstrapper/Program.cs index 04144fa5..9985c164 100644 --- a/src/dotnet-bootstrapper/Program.cs +++ b/src/dotnet-bootstrapper/Program.cs @@ -12,19 +12,6 @@ class Program { static int Main(string[] args) { - var rootCommand = new RootCommand("dotnet bootstrapper"); - - var installCommand = new Command("install", "Install the specified version of the .NET SDK.") - { - new Argument("version") - { - Description = "The version of the .NET SDK to install.", - Arity = ArgumentArity.ExactlyOne - } - }; - - rootCommand.AddCommand(installCommand); - - return rootCommand.Invoke(args); + return BootstrapperCommandParser.BootstrapParser.InvokeAsync(args).Result; } } diff --git a/test/dotnet-bootstrapper.Tests/EndToEndTests.cs b/test/dotnet-bootstrapper.Tests/EndToEndTests.cs index b80d63b7..5b0456ac 100644 --- a/test/dotnet-bootstrapper.Tests/EndToEndTests.cs +++ b/test/dotnet-bootstrapper.Tests/EndToEndTests.cs @@ -31,7 +31,8 @@ internal void ItReturnsZeroOnExit() RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, - CreateNoWindow = true + CreateNoWindow = true, + Arguments = "--version" } }; From 5ca0b5c6e74b6a3835d10570db3a6d478821db23 Mon Sep 17 00:00:00 2001 From: Forgind <12969783+Forgind@users.noreply.github.com> Date: Mon, 21 Apr 2025 16:11:06 -0700 Subject: [PATCH 4/8] Try using uninstall commands --- .../BootstrapperCommandParser.cs | 26 +++++-------------- .../LocalizableStrings.resx | 3 +++ .../dotnet-bootstrapper.csproj | 1 + .../xlf/LocalizableStrings.cs.xlf | 8 +++++- .../xlf/LocalizableStrings.de.xlf | 8 +++++- .../xlf/LocalizableStrings.es.xlf | 8 +++++- .../xlf/LocalizableStrings.fr.xlf | 8 +++++- .../xlf/LocalizableStrings.it.xlf | 8 +++++- .../xlf/LocalizableStrings.ja.xlf | 8 +++++- .../xlf/LocalizableStrings.ko.xlf | 8 +++++- .../xlf/LocalizableStrings.pl.xlf | 8 +++++- .../xlf/LocalizableStrings.pt-BR.xlf | 8 +++++- .../xlf/LocalizableStrings.ru.xlf | 8 +++++- .../xlf/LocalizableStrings.tr.xlf | 8 +++++- .../xlf/LocalizableStrings.zh-Hans.xlf | 8 +++++- .../xlf/LocalizableStrings.zh-Hant.xlf | 8 +++++- .../Shared/Configs/CommandLineConfigs.cs | 2 ++ .../dotnet-core-uninstall.csproj | 1 + 18 files changed, 105 insertions(+), 32 deletions(-) diff --git a/src/dotnet-bootstrapper/BootstrapperCommandParser.cs b/src/dotnet-bootstrapper/BootstrapperCommandParser.cs index e754a6ae..ef6b8137 100644 --- a/src/dotnet-bootstrapper/BootstrapperCommandParser.cs +++ b/src/dotnet-bootstrapper/BootstrapperCommandParser.cs @@ -7,6 +7,7 @@ using System.CommandLine.Invocation; using System.CommandLine.Parsing; using System.Reflection; +using Microsoft.DotNet.Tools.Uninstall.Shared.Configs; namespace Microsoft.DotNet.Tools.Bootstrapper { @@ -15,30 +16,17 @@ internal static class BootstrapperCommandParser public static Parser BootstrapParser; public static RootCommand BootstrapperRootCommand = new RootCommand("dotnet bootstrapper"); - - public static readonly Command VersionCommand = new Command("--version"); - - private static readonly Lazy _assemblyVersion = - new Lazy(() => - { - var assembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly(); - var assemblyVersionAttribute = assembly.GetCustomAttribute(); - if (assemblyVersionAttribute == null) - { - return assembly.GetName().Version.ToString(); - } - else - { - return assemblyVersionAttribute.InformationalVersion; - } - }); + public static readonly Command HelpCommand = new("--help"); static BootstrapperCommandParser() { - BootstrapperRootCommand.AddCommand(VersionCommand); + BootstrapperRootCommand.AddCommand(CommandLineConfigs.VersionSubcommand); + BootstrapperRootCommand.AddCommand(CommandLineConfigs.ListCommand); + BootstrapperRootCommand.AddCommand(CommandLineConfigs.RemoveCommand); + BootstrapperRootCommand.AddCommand(HelpCommand); VersionCommand.Handler = CommandHandler.Create(() => { - Console.WriteLine(_assemblyVersion.Value); + Console.WriteLine(LocalizableStrings.BootstrapperHelp); }); BootstrapParser = new CommandLineBuilder(BootstrapperRootCommand) diff --git a/src/dotnet-bootstrapper/LocalizableStrings.resx b/src/dotnet-bootstrapper/LocalizableStrings.resx index 8b2ff64a..85e4edd0 100644 --- a/src/dotnet-bootstrapper/LocalizableStrings.resx +++ b/src/dotnet-bootstrapper/LocalizableStrings.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Bootstrapper help text + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/dotnet-bootstrapper.csproj b/src/dotnet-bootstrapper/dotnet-bootstrapper.csproj index 3c081deb..1f570479 100644 --- a/src/dotnet-bootstrapper/dotnet-bootstrapper.csproj +++ b/src/dotnet-bootstrapper/dotnet-bootstrapper.csproj @@ -25,6 +25,7 @@ + diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.cs.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.cs.xlf index e028ecc8..62e39f34 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.cs.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.cs.xlf @@ -1,6 +1,12 @@  - + + + Bootstrapper help text + Bootstrapper help text + + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.de.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.de.xlf index 02f57c3c..b900a85c 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.de.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.de.xlf @@ -1,6 +1,12 @@  - + + + Bootstrapper help text + Bootstrapper help text + + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.es.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.es.xlf index bd51c90f..1bdf68b3 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.es.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.es.xlf @@ -1,6 +1,12 @@  - + + + Bootstrapper help text + Bootstrapper help text + + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.fr.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.fr.xlf index 353aa168..3faf4859 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.fr.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.fr.xlf @@ -1,6 +1,12 @@  - + + + Bootstrapper help text + Bootstrapper help text + + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.it.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.it.xlf index 8521fc88..0fe72bf7 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.it.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.it.xlf @@ -1,6 +1,12 @@  - + + + Bootstrapper help text + Bootstrapper help text + + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.ja.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.ja.xlf index a4bdbd56..b99ec495 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.ja.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.ja.xlf @@ -1,6 +1,12 @@  - + + + Bootstrapper help text + Bootstrapper help text + + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.ko.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.ko.xlf index dfe7ff8c..5291085c 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.ko.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.ko.xlf @@ -1,6 +1,12 @@  - + + + Bootstrapper help text + Bootstrapper help text + + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.pl.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.pl.xlf index edb8d7de..5fb33884 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.pl.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.pl.xlf @@ -1,6 +1,12 @@  - + + + Bootstrapper help text + Bootstrapper help text + + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.pt-BR.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.pt-BR.xlf index 616bbc89..5275a2d0 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.pt-BR.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.pt-BR.xlf @@ -1,6 +1,12 @@  - + + + Bootstrapper help text + Bootstrapper help text + + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.ru.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.ru.xlf index 8e47a5f3..f8ddcba8 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.ru.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.ru.xlf @@ -1,6 +1,12 @@  - + + + Bootstrapper help text + Bootstrapper help text + + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.tr.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.tr.xlf index 770cdf4a..d4074d68 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.tr.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.tr.xlf @@ -1,6 +1,12 @@  - + + + Bootstrapper help text + Bootstrapper help text + + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.zh-Hans.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.zh-Hans.xlf index 1832bb6c..94caddf0 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.zh-Hans.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.zh-Hans.xlf @@ -1,6 +1,12 @@  - + + + Bootstrapper help text + Bootstrapper help text + + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.zh-Hant.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.zh-Hant.xlf index 4a6c48aa..28886312 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.zh-Hant.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.zh-Hant.xlf @@ -1,6 +1,12 @@  - + + + Bootstrapper help text + Bootstrapper help text + + + \ No newline at end of file diff --git a/src/dotnet-core-uninstall/Shared/Configs/CommandLineConfigs.cs b/src/dotnet-core-uninstall/Shared/Configs/CommandLineConfigs.cs index 863b07c8..290e6df1 100644 --- a/src/dotnet-core-uninstall/Shared/Configs/CommandLineConfigs.cs +++ b/src/dotnet-core-uninstall/Shared/Configs/CommandLineConfigs.cs @@ -28,6 +28,7 @@ internal static class CommandLineConfigs private static readonly string DryRunCommandName = "dry-run"; private static readonly string WhatIfCommandName = "whatif"; private static readonly string RemoveCommandName = "remove"; + private static readonly string UninstallCommandName = "uninstall"; public static readonly RootCommand UninstallRootCommand = new RootCommand( RuntimeInfo.RunningOnWindows ? LocalizableStrings.UninstallNoOptionDescriptionWindows @@ -220,6 +221,7 @@ static CommandLineConfigs() UninstallRootCommand.AddCommand(ListCommand); UninstallRootCommand.AddCommand(DryRunCommand); UninstallRootCommand.AddCommand(RemoveCommand); + RemoveCommand.Aliases.Add(UninstallCommandName); // The verbiage that makes the most sense from the bootstrapper would be 'uninstall', so just adding an alias permits more code sharing UninstallRootCommand.AddCommand(VersionSubcommand); if (RuntimeInfo.RunningOnOSX) diff --git a/src/dotnet-core-uninstall/dotnet-core-uninstall.csproj b/src/dotnet-core-uninstall/dotnet-core-uninstall.csproj index fd483523..5f61daa7 100644 --- a/src/dotnet-core-uninstall/dotnet-core-uninstall.csproj +++ b/src/dotnet-core-uninstall/dotnet-core-uninstall.csproj @@ -2,6 +2,7 @@ dotnet-core-uninstall Exe + true win-x86;osx-x64;osx-arm64 true net8.0 From 80beb9c829e9f3e805417bf06322ae741f1446e9 Mon Sep 17 00:00:00 2001 From: Forgind <12969783+Forgind@users.noreply.github.com> Date: Mon, 21 Apr 2025 18:25:20 -0700 Subject: [PATCH 5/8] Little push --- src/dotnet-bootstrapper/BootstrapperCommandParser.cs | 2 +- .../Shared/Configs/CommandLineConfigs.cs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/dotnet-bootstrapper/BootstrapperCommandParser.cs b/src/dotnet-bootstrapper/BootstrapperCommandParser.cs index ef6b8137..f4ff9a15 100644 --- a/src/dotnet-bootstrapper/BootstrapperCommandParser.cs +++ b/src/dotnet-bootstrapper/BootstrapperCommandParser.cs @@ -24,7 +24,7 @@ static BootstrapperCommandParser() BootstrapperRootCommand.AddCommand(CommandLineConfigs.ListCommand); BootstrapperRootCommand.AddCommand(CommandLineConfigs.RemoveCommand); BootstrapperRootCommand.AddCommand(HelpCommand); - VersionCommand.Handler = CommandHandler.Create(() => + HelpCommand.Handler = CommandHandler.Create(() => { Console.WriteLine(LocalizableStrings.BootstrapperHelp); }); diff --git a/src/dotnet-core-uninstall/Shared/Configs/CommandLineConfigs.cs b/src/dotnet-core-uninstall/Shared/Configs/CommandLineConfigs.cs index 290e6df1..23935d08 100644 --- a/src/dotnet-core-uninstall/Shared/Configs/CommandLineConfigs.cs +++ b/src/dotnet-core-uninstall/Shared/Configs/CommandLineConfigs.cs @@ -20,7 +20,7 @@ namespace Microsoft.DotNet.Tools.Uninstall.Shared.Configs { - internal static class CommandLineConfigs + public static class CommandLineConfigs { public static Parser UninstallCommandParser; @@ -185,7 +185,7 @@ internal static class CommandLineConfigs ForceOption }; - public static readonly Dictionary VerbosityLevels = new Dictionary + internal static readonly Dictionary VerbosityLevels = new Dictionary { { "q", VerbosityLevel.Quiet }, { "quiet", VerbosityLevel.Quiet }, { "m", VerbosityLevel.Minimal }, { "minimal", VerbosityLevel.Minimal }, @@ -221,7 +221,7 @@ static CommandLineConfigs() UninstallRootCommand.AddCommand(ListCommand); UninstallRootCommand.AddCommand(DryRunCommand); UninstallRootCommand.AddCommand(RemoveCommand); - RemoveCommand.Aliases.Add(UninstallCommandName); // The verbiage that makes the most sense from the bootstrapper would be 'uninstall', so just adding an alias permits more code sharing + RemoveCommand.AddAlias(UninstallCommandName); // The verbiage that makes the most sense from the bootstrapper would be 'uninstall', so just adding an alias permits more code sharing UninstallRootCommand.AddCommand(VersionSubcommand); if (RuntimeInfo.RunningOnOSX) @@ -314,7 +314,7 @@ public static Option GetUninstallMainOption(this CommandResult commandResult) return specifiedOption; } - public static BundleType GetTypeSelection(this ParseResult parseResult) + internal static BundleType GetTypeSelection(this ParseResult parseResult) { var supportedBundleTypes = SupportedBundleTypeConfigs.GetSupportedBundleTypes(); @@ -328,7 +328,7 @@ public static BundleType GetTypeSelection(this ParseResult parseResult) typeSelection; } - public static BundleArch GetArchSelection(this ParseResult parseResult) + internal static BundleArch GetArchSelection(this ParseResult parseResult) { var archSelection = new[] { @@ -345,7 +345,7 @@ public static BundleArch GetArchSelection(this ParseResult parseResult) archSelection; } - public static VerbosityLevel GetVerbosityLevel(this CommandResult commandResult) + internal static VerbosityLevel GetVerbosityLevel(this CommandResult commandResult) { var optionResult = commandResult.FindResultFor(VerbosityOption); From 704ceaac3790930940b5fc6ee3abc30415b0a441 Mon Sep 17 00:00:00 2001 From: Forgind <12969783+Forgind@users.noreply.github.com> Date: Wed, 30 Apr 2025 14:47:48 -0700 Subject: [PATCH 6/8] Revert "Remove LocalizableStrings.Designer.cs" This reverts commit 71777a1606e63fb07103c4b82ce1e88403e3859e. --- .../LocalizableStrings.Designer.cs | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/dotnet-bootstrapper/LocalizableStrings.Designer.cs diff --git a/src/dotnet-bootstrapper/LocalizableStrings.Designer.cs b/src/dotnet-bootstrapper/LocalizableStrings.Designer.cs new file mode 100644 index 00000000..8ff3e4a7 --- /dev/null +++ b/src/dotnet-bootstrapper/LocalizableStrings.Designer.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Microsoft.DotNet.Tools.Uninstall +{ + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class LocalizableStrings + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal LocalizableStrings() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if (object.ReferenceEquals(resourceMan, null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.DotNet.Tools.Uninstall.LocalizableStrings", typeof(LocalizableStrings).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} From 69ca8e3443725ecad3caafbaef7edbb15e2a471c Mon Sep 17 00:00:00 2001 From: Forgind <12969783+Forgind@users.noreply.github.com> Date: Thu, 1 May 2025 16:45:53 -0700 Subject: [PATCH 7/8] Work on real implementations --- .../BootstrapperCommandParser.cs | 145 ++++++++++++++++-- .../LocalizableStrings.Designer.cs | 70 +++++---- .../LocalizableStrings.resx | 60 ++++---- .../dotnet-bootstrapper.csproj | 5 +- .../xlf/LocalizableStrings.cs.xlf | 10 ++ .../xlf/LocalizableStrings.de.xlf | 10 ++ .../xlf/LocalizableStrings.es.xlf | 10 ++ .../xlf/LocalizableStrings.fr.xlf | 10 ++ .../xlf/LocalizableStrings.it.xlf | 10 ++ .../xlf/LocalizableStrings.ja.xlf | 10 ++ .../xlf/LocalizableStrings.ko.xlf | 10 ++ .../xlf/LocalizableStrings.pl.xlf | 10 ++ .../xlf/LocalizableStrings.pt-BR.xlf | 10 ++ .../xlf/LocalizableStrings.ru.xlf | 10 ++ .../xlf/LocalizableStrings.tr.xlf | 10 ++ .../xlf/LocalizableStrings.zh-Hans.xlf | 10 ++ .../xlf/LocalizableStrings.zh-Hant.xlf | 10 ++ .../Shared/Exceptions/ExceptionHandler.cs | 4 +- 18 files changed, 345 insertions(+), 69 deletions(-) diff --git a/src/dotnet-bootstrapper/BootstrapperCommandParser.cs b/src/dotnet-bootstrapper/BootstrapperCommandParser.cs index f4ff9a15..f5598598 100644 --- a/src/dotnet-bootstrapper/BootstrapperCommandParser.cs +++ b/src/dotnet-bootstrapper/BootstrapperCommandParser.cs @@ -1,13 +1,18 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Collections; +using System.Collections.Generic; using System.CommandLine; using System.CommandLine.Builder; +using System.CommandLine.Help; using System.CommandLine.Invocation; using System.CommandLine.Parsing; +using System.IO; +using System.Linq; using System.Reflection; -using Microsoft.DotNet.Tools.Uninstall.Shared.Configs; +using System.Runtime.InteropServices; namespace Microsoft.DotNet.Tools.Bootstrapper { @@ -16,22 +21,140 @@ internal static class BootstrapperCommandParser public static Parser BootstrapParser; public static RootCommand BootstrapperRootCommand = new RootCommand("dotnet bootstrapper"); - public static readonly Command HelpCommand = new("--help"); - static BootstrapperCommandParser() + public static readonly Command VersionCommand = new("--version") { - BootstrapperRootCommand.AddCommand(CommandLineConfigs.VersionSubcommand); - BootstrapperRootCommand.AddCommand(CommandLineConfigs.ListCommand); - BootstrapperRootCommand.AddCommand(CommandLineConfigs.RemoveCommand); - BootstrapperRootCommand.AddCommand(HelpCommand); - HelpCommand.Handler = CommandHandler.Create(() => + Handler = CommandHandler.Create(() => + { + Assembly assembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly(); + Console.WriteLine(assembly.GetCustomAttribute()?.InformationalVersion ?? assembly.GetName().Version.ToString()); + }) + }; + + public static readonly Command HelpCommand = new("--help") + { + Handler = CommandHandler.Create(() => { Console.WriteLine(LocalizableStrings.BootstrapperHelp); - }); + }) + }; + + public static readonly Command ListCommand = new("list", LocalizableStrings.ListCommandDescription) + { + Handler = CommandHandler.Create(() => + { + string dotnetDir = FindLocalDotnet(); + if (dotnetDir is null) + { + Console.WriteLine("dotnet executable not found. Ensure you execute this command from a directory with it."); + return; + } + + foreach (string s in FindLocalSDKs(dotnetDir)) + { + Console.WriteLine(s); + } + }) + }; + + public static readonly Command UninstallCommand = new("uninstall", LocalizableStrings.UninstallCommandDescription) + { + Handler = CommandHandler.Create((ParseResult parseResult) => + { + string dotnetDir = FindLocalDotnet(); + if (dotnetDir is null) + { + Console.WriteLine("dotnet executable not found. Ensure you execute this command from a directory with it."); + return; + } + + string sdkToUninstall = parseResult.ValueForArgument(UninstallArgument); + + IEnumerable localSdks = FindLocalSDKs(dotnetDir).Where(sdk => sdk.EndsWith("foo")); + if (!localSdks.Any()) + { + Console.WriteLine("Failed to find SDK " + "foo"); + return; + } + + string sdkFolder = Path.Combine(Path.GetDirectoryName(dotnetDir), "sdk"); + foreach (string sdk in localSdks) + { + Console.WriteLine("Deleting SDK " + sdk); + Directory.Delete(sdk, recursive: true); + } + }) + }; + + public static readonly Argument UninstallArgument = new() + { + Name = "uninstall", + Arity = ArgumentArity.ExactlyOne + }; + + internal enum hostfxr_resolve_sdk2_result_key_t + { + resolved_sdk_dir = 0, + global_json_path = 1, + }; + + [DllImport("hostfxr", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] + internal static extern int hostfxr_get_available_sdks(string exe_dir, hostfxr_get_available_sdks_result_fn result); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Auto)] + internal delegate void hostfxr_get_available_sdks_result_fn( + hostfxr_resolve_sdk2_result_key_t key, + [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] + string[] value); + + private static string[] FindLocalSDKs(string dotnetDir) + { + string[] resolvedPaths = null; + int returnCode = hostfxr_get_available_sdks(exe_dir: dotnetDir, result: (key, value) => resolvedPaths = value); + if (returnCode == 0) + { + return resolvedPaths ?? []; + } + else + { + throw new InvalidOperationException("Failed to find SDKs"); + } + } + + private static string FindLocalDotnet() + { + string currentDirectory = Directory.GetCurrentDirectory(); + return CheckFile(currentDirectory) ?? + CheckFile(Path.GetDirectoryName(currentDirectory)) ?? + Directory.GetDirectories(currentDirectory).SelectMany(subdirectory => + { + if (CheckFile(subdirectory) is string subDotnet) + { + return [subDotnet]; + } + + return Directory.GetDirectories(subdirectory).Select(CheckFile); + }).FirstOrDefault(path => path is not null); + } + + private static string CheckFile(string directory) + { + string fileToCheck = Path.Combine(directory, "dotnet.exe"); + return File.Exists(fileToCheck) ? fileToCheck : null; + } + + static BootstrapperCommandParser() + { + BootstrapperRootCommand.AddCommand(VersionCommand); + BootstrapperRootCommand.AddCommand(HelpCommand); + BootstrapperRootCommand.AddCommand(ListCommand); + BootstrapperRootCommand.AddCommand(UninstallCommand); + + UninstallCommand.AddArgument(UninstallArgument); BootstrapParser = new CommandLineBuilder(BootstrapperRootCommand) .UseDefaults() - // .UseHelpBuilder(context => new UninstallHelpBuilder(context.Console)) + .UseHelpBuilder(context => new HelpBuilder(context.Console)) .Build(); } } diff --git a/src/dotnet-bootstrapper/LocalizableStrings.Designer.cs b/src/dotnet-bootstrapper/LocalizableStrings.Designer.cs index 8ff3e4a7..85bffac8 100644 --- a/src/dotnet-bootstrapper/LocalizableStrings.Designer.cs +++ b/src/dotnet-bootstrapper/LocalizableStrings.Designer.cs @@ -8,11 +8,10 @@ // //------------------------------------------------------------------------------ -namespace Microsoft.DotNet.Tools.Uninstall -{ +namespace Microsoft.DotNet.Tools.Bootstrapper { using System; - - + + /// /// A strongly-typed resource class, for looking up localized strings, etc. /// @@ -23,50 +22,69 @@ namespace Microsoft.DotNet.Tools.Uninstall [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class LocalizableStrings - { - + internal class LocalizableStrings { + private static global::System.Resources.ResourceManager resourceMan; - + private static global::System.Globalization.CultureInfo resourceCulture; - + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal LocalizableStrings() - { + internal LocalizableStrings() { } - + /// /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if (object.ReferenceEquals(resourceMan, null)) - { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.DotNet.Tools.Uninstall.LocalizableStrings", typeof(LocalizableStrings).Assembly); + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.DotNet.Tools.Bootstrapper.LocalizableStrings", typeof(LocalizableStrings).Assembly); resourceMan = temp; } return resourceMan; } } - + /// /// Overrides the current thread's CurrentUICulture property for all /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { + internal static global::System.Globalization.CultureInfo Culture { + get { return resourceCulture; } - set - { + set { resourceCulture = value; } } + + /// + /// Looks up a localized string similar to Bootstrapper help text. + /// + internal static string BootstrapperHelp { + get { + return ResourceManager.GetString("BootstrapperHelp", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to List out all currently installed SDKs.. + /// + internal static string ListCommandDescription { + get { + return ResourceManager.GetString("ListCommandDescription", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Uninstall the specified SDK.. + /// + internal static string UninstallCommandDescription { + get { + return ResourceManager.GetString("UninstallCommandDescription", resourceCulture); + } + } } } diff --git a/src/dotnet-bootstrapper/LocalizableStrings.resx b/src/dotnet-bootstrapper/LocalizableStrings.resx index 85e4edd0..e7a9b618 100644 --- a/src/dotnet-bootstrapper/LocalizableStrings.resx +++ b/src/dotnet-bootstrapper/LocalizableStrings.resx @@ -1,17 +1,17 @@  - @@ -120,4 +120,10 @@ Bootstrapper help text + + List out all currently installed SDKs. + + + Uninstall the specified SDK. + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/dotnet-bootstrapper.csproj b/src/dotnet-bootstrapper/dotnet-bootstrapper.csproj index 1f570479..a4a49cbc 100644 --- a/src/dotnet-bootstrapper/dotnet-bootstrapper.csproj +++ b/src/dotnet-bootstrapper/dotnet-bootstrapper.csproj @@ -3,12 +3,11 @@ dotnet-bootstrapper Exe true + win-x86;osx-x64;osx-arm64 true net8.0 true true - false - true true true LatestMajor @@ -17,6 +16,7 @@ preview Microsoft.DotNet.Tools.Bootstrapper + Microsoft.DotNet.Tools.Bootstrapper @@ -25,7 +25,6 @@ - diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.cs.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.cs.xlf index 62e39f34..6424f74b 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.cs.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.cs.xlf @@ -7,6 +7,16 @@ Bootstrapper help text + + List out all currently installed SDKs. + List out all currently installed SDKs. + + + + Uninstall the specified SDK. + Uninstall the specified SDK. + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.de.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.de.xlf index b900a85c..55485d8f 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.de.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.de.xlf @@ -7,6 +7,16 @@ Bootstrapper help text + + List out all currently installed SDKs. + List out all currently installed SDKs. + + + + Uninstall the specified SDK. + Uninstall the specified SDK. + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.es.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.es.xlf index 1bdf68b3..85c8c3e5 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.es.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.es.xlf @@ -7,6 +7,16 @@ Bootstrapper help text + + List out all currently installed SDKs. + List out all currently installed SDKs. + + + + Uninstall the specified SDK. + Uninstall the specified SDK. + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.fr.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.fr.xlf index 3faf4859..a5c8fc49 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.fr.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.fr.xlf @@ -7,6 +7,16 @@ Bootstrapper help text + + List out all currently installed SDKs. + List out all currently installed SDKs. + + + + Uninstall the specified SDK. + Uninstall the specified SDK. + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.it.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.it.xlf index 0fe72bf7..a619fc37 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.it.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.it.xlf @@ -7,6 +7,16 @@ Bootstrapper help text + + List out all currently installed SDKs. + List out all currently installed SDKs. + + + + Uninstall the specified SDK. + Uninstall the specified SDK. + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.ja.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.ja.xlf index b99ec495..ff133c70 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.ja.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.ja.xlf @@ -7,6 +7,16 @@ Bootstrapper help text + + List out all currently installed SDKs. + List out all currently installed SDKs. + + + + Uninstall the specified SDK. + Uninstall the specified SDK. + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.ko.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.ko.xlf index 5291085c..5aa7b3bd 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.ko.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.ko.xlf @@ -7,6 +7,16 @@ Bootstrapper help text + + List out all currently installed SDKs. + List out all currently installed SDKs. + + + + Uninstall the specified SDK. + Uninstall the specified SDK. + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.pl.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.pl.xlf index 5fb33884..16856889 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.pl.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.pl.xlf @@ -7,6 +7,16 @@ Bootstrapper help text + + List out all currently installed SDKs. + List out all currently installed SDKs. + + + + Uninstall the specified SDK. + Uninstall the specified SDK. + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.pt-BR.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.pt-BR.xlf index 5275a2d0..f42d8714 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.pt-BR.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.pt-BR.xlf @@ -7,6 +7,16 @@ Bootstrapper help text + + List out all currently installed SDKs. + List out all currently installed SDKs. + + + + Uninstall the specified SDK. + Uninstall the specified SDK. + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.ru.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.ru.xlf index f8ddcba8..e723ebec 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.ru.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.ru.xlf @@ -7,6 +7,16 @@ Bootstrapper help text + + List out all currently installed SDKs. + List out all currently installed SDKs. + + + + Uninstall the specified SDK. + Uninstall the specified SDK. + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.tr.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.tr.xlf index d4074d68..9b43f0a4 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.tr.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.tr.xlf @@ -7,6 +7,16 @@ Bootstrapper help text + + List out all currently installed SDKs. + List out all currently installed SDKs. + + + + Uninstall the specified SDK. + Uninstall the specified SDK. + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.zh-Hans.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.zh-Hans.xlf index 94caddf0..6ddf01bf 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.zh-Hans.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.zh-Hans.xlf @@ -7,6 +7,16 @@ Bootstrapper help text + + List out all currently installed SDKs. + List out all currently installed SDKs. + + + + Uninstall the specified SDK. + Uninstall the specified SDK. + + \ No newline at end of file diff --git a/src/dotnet-bootstrapper/xlf/LocalizableStrings.zh-Hant.xlf b/src/dotnet-bootstrapper/xlf/LocalizableStrings.zh-Hant.xlf index 28886312..554bda39 100644 --- a/src/dotnet-bootstrapper/xlf/LocalizableStrings.zh-Hant.xlf +++ b/src/dotnet-bootstrapper/xlf/LocalizableStrings.zh-Hant.xlf @@ -7,6 +7,16 @@ Bootstrapper help text + + List out all currently installed SDKs. + List out all currently installed SDKs. + + + + Uninstall the specified SDK. + Uninstall the specified SDK. + + \ No newline at end of file diff --git a/src/dotnet-core-uninstall/Shared/Exceptions/ExceptionHandler.cs b/src/dotnet-core-uninstall/Shared/Exceptions/ExceptionHandler.cs index 2497d18e..ec6007de 100644 --- a/src/dotnet-core-uninstall/Shared/Exceptions/ExceptionHandler.cs +++ b/src/dotnet-core-uninstall/Shared/Exceptions/ExceptionHandler.cs @@ -9,11 +9,11 @@ internal static class ExceptionHandler { public static Action HandleException(Action action) { - return (x) => + return x => { try { - action.Invoke(x); + action(x); } catch (DotNetUninstallException e) { From a9a45f3afb05814bb8b2bc9c5e7f58d04175b182 Mon Sep 17 00:00:00 2001 From: Forgind <12969783+Forgind@users.noreply.github.com> Date: Thu, 15 May 2025 11:51:55 -0700 Subject: [PATCH 8/8] Random incomplete changes --- .../BootstrapperCommandParser.cs | 65 +++++++++++++++++-- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/src/dotnet-bootstrapper/BootstrapperCommandParser.cs b/src/dotnet-bootstrapper/BootstrapperCommandParser.cs index f5598598..547300f9 100644 --- a/src/dotnet-bootstrapper/BootstrapperCommandParser.cs +++ b/src/dotnet-bootstrapper/BootstrapperCommandParser.cs @@ -13,6 +13,7 @@ using System.Linq; using System.Reflection; using System.Runtime.InteropServices; +using System.Text.Json; namespace Microsoft.DotNet.Tools.Bootstrapper { @@ -41,9 +42,9 @@ internal static class BootstrapperCommandParser public static readonly Command ListCommand = new("list", LocalizableStrings.ListCommandDescription) { - Handler = CommandHandler.Create(() => + Handler = CommandHandler.Create((ParseResult parseResult) => { - string dotnetDir = FindLocalDotnet(); + string dotnetDir = FindLocalDotnet(parseResult.ValueForOption(DotnetPath)); if (dotnetDir is null) { Console.WriteLine("dotnet executable not found. Ensure you execute this command from a directory with it."); @@ -61,7 +62,7 @@ internal static class BootstrapperCommandParser { Handler = CommandHandler.Create((ParseResult parseResult) => { - string dotnetDir = FindLocalDotnet(); + string dotnetDir = FindLocalDotnet(parseResult.ValueForOption(DotnetPath)); if (dotnetDir is null) { Console.WriteLine("dotnet executable not found. Ensure you execute this command from a directory with it."); @@ -86,12 +87,26 @@ internal static class BootstrapperCommandParser }) }; + public static readonly Command InstallCommand = new("install", LocalizableStrings.InstallCommandDescription) + { + Handler = CommandHandler.Create((ParseResult parseResult) => + { + string dotnetDir = FindLocalDotnet(parseResult.ValueForOption(DotnetPath)); + if (dotnetDir is null) + { + // install dotnet.exe + } + }) + }; + public static readonly Argument UninstallArgument = new() { Name = "uninstall", Arity = ArgumentArity.ExactlyOne }; + public static readonly Option DotnetPath = new("--dotnetPath", getDefaultValue: () => null); + internal enum hostfxr_resolve_sdk2_result_key_t { resolved_sdk_dir = 0, @@ -121,9 +136,27 @@ private static string[] FindLocalSDKs(string dotnetDir) } } - private static string FindLocalDotnet() + private static string FindLocalDotnet(string pathFromSwitch) { + if (pathFromSwitch is not null) + { + string pathToDotnet = CheckFile(pathFromSwitch) ?? pathFromSwitch; + if (!File.Exists(pathToDotnet)) + { + throw new ArgumentException($"Path {pathFromSwitch} does not lead to the dotnet executable."); + } + + return pathToDotnet; + } + string currentDirectory = Directory.GetCurrentDirectory(); + + string path = FindAndParseGlobalJson(currentDirectory); + if (path is not null) + { + return path; + } + return CheckFile(currentDirectory) ?? CheckFile(Path.GetDirectoryName(currentDirectory)) ?? Directory.GetDirectories(currentDirectory).SelectMany(subdirectory => @@ -137,6 +170,25 @@ private static string FindLocalDotnet() }).FirstOrDefault(path => path is not null); } + private static string FindAndParseGlobalJson(string startingDirectory) + { + string currentDirectory = startingDirectory; + string globalJsonPath = Path.Combine(currentDirectory, "global.json"); + while (!File.Exists(globalJsonPath)) + { + startingDirectory = Path.GetDirectoryName(startingDirectory); + if (startingDirectory is null) + { + return null; + } + + globalJsonPath = Path.Combine(currentDirectory, "global.json"); + } + + JsonDocument jsonDocument = JsonDocument.Parse(globalJsonPath); + jsonDocument.RootElement. + } + private static string CheckFile(string directory) { string fileToCheck = Path.Combine(directory, "dotnet.exe"); @@ -149,6 +201,11 @@ static BootstrapperCommandParser() BootstrapperRootCommand.AddCommand(HelpCommand); BootstrapperRootCommand.AddCommand(ListCommand); BootstrapperRootCommand.AddCommand(UninstallCommand); + BootstrapperRootCommand.AddCommand(InstallCommand); + + ListCommand.AddOption(DotnetPath); + UninstallCommand.AddOption(DotnetPath); + InstallCommand.AddOption(DotnetPath); UninstallCommand.AddArgument(UninstallArgument);