From 5fd9d9441f88d9a2a0086ebeeb1d53f0c0413cfe Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Oct 2025 15:17:33 +0000 Subject: [PATCH 1/3] Initial plan From 4f77a1a93f17d85f1333e8b195d99590aedb6ac6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Oct 2025 15:27:53 +0000 Subject: [PATCH 2/3] Update CLI version notification to include update instructions - Modified InteractionServiceStrings.resx to include update command parameter - Updated ConsoleInteractionService to detect if running as dotnet tool - Shows "aspire update --self" for native binary - Shows "dotnet tool update aspire.cli" for dotnet tool - Updated Designer.cs for resource strings - Added test to verify update message includes command Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com> --- .../Interaction/ConsoleInteractionService.cs | 22 +++++++++++++- .../InteractionServiceStrings.Designer.cs | 2 +- .../Resources/InteractionServiceStrings.resx | 4 +-- .../xlf/InteractionServiceStrings.cs.xlf | 6 ++-- .../xlf/InteractionServiceStrings.de.xlf | 6 ++-- .../xlf/InteractionServiceStrings.es.xlf | 6 ++-- .../xlf/InteractionServiceStrings.fr.xlf | 6 ++-- .../xlf/InteractionServiceStrings.it.xlf | 6 ++-- .../xlf/InteractionServiceStrings.ja.xlf | 6 ++-- .../xlf/InteractionServiceStrings.ko.xlf | 6 ++-- .../xlf/InteractionServiceStrings.pl.xlf | 6 ++-- .../xlf/InteractionServiceStrings.pt-BR.xlf | 6 ++-- .../xlf/InteractionServiceStrings.ru.xlf | 6 ++-- .../xlf/InteractionServiceStrings.tr.xlf | 6 ++-- .../xlf/InteractionServiceStrings.zh-Hans.xlf | 6 ++-- .../xlf/InteractionServiceStrings.zh-Hant.xlf | 6 ++-- .../ConsoleInteractionServiceTests.cs | 29 +++++++++++++++++++ 17 files changed, 92 insertions(+), 43 deletions(-) diff --git a/src/Aspire.Cli/Interaction/ConsoleInteractionService.cs b/src/Aspire.Cli/Interaction/ConsoleInteractionService.cs index 01f65a6b816..2221e168b74 100644 --- a/src/Aspire.Cli/Interaction/ConsoleInteractionService.cs +++ b/src/Aspire.Cli/Interaction/ConsoleInteractionService.cs @@ -246,7 +246,27 @@ public void DisplayEmptyLine() public void DisplayVersionUpdateNotification(string newerVersion) { _ansiConsole.WriteLine(); - _ansiConsole.MarkupLine(string.Format(CultureInfo.CurrentCulture, InteractionServiceStrings.NewCliVersionAvailable, newerVersion)); + + // Determine the update command based on how the CLI is running + var updateCommand = IsRunningAsDotNetTool() + ? "dotnet tool update aspire.cli" + : "aspire update --self"; + + _ansiConsole.MarkupLine(string.Format(CultureInfo.CurrentCulture, InteractionServiceStrings.NewCliVersionAvailable, newerVersion, updateCommand)); _ansiConsole.MarkupLine(string.Format(CultureInfo.CurrentCulture, InteractionServiceStrings.MoreInfoNewCliVersion, UpdateUrl)); } + + private static bool IsRunningAsDotNetTool() + { + // When running as a dotnet tool, the process path points to "dotnet" or "dotnet.exe" + // When running as a native binary, it points to "aspire" or "aspire.exe" + var processPath = Environment.ProcessPath; + if (string.IsNullOrEmpty(processPath)) + { + return false; + } + + var fileName = Path.GetFileNameWithoutExtension(processPath); + return string.Equals(fileName, "dotnet", StringComparison.OrdinalIgnoreCase); + } } diff --git a/src/Aspire.Cli/Resources/InteractionServiceStrings.Designer.cs b/src/Aspire.Cli/Resources/InteractionServiceStrings.Designer.cs index 600c46cfad0..f1181910da7 100644 --- a/src/Aspire.Cli/Resources/InteractionServiceStrings.Designer.cs +++ b/src/Aspire.Cli/Resources/InteractionServiceStrings.Designer.cs @@ -196,7 +196,7 @@ public static string MoreInfoNewCliVersion { } /// - /// Looks up a localized string similar to [yellow]A new version of the Aspire CLI is available: {0}[/]. + /// Looks up a localized string similar to [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/]. /// public static string NewCliVersionAvailable { get { diff --git a/src/Aspire.Cli/Resources/InteractionServiceStrings.resx b/src/Aspire.Cli/Resources/InteractionServiceStrings.resx index c1409e5776d..22bf35eb6ca 100644 --- a/src/Aspire.Cli/Resources/InteractionServiceStrings.resx +++ b/src/Aspire.Cli/Resources/InteractionServiceStrings.resx @@ -201,8 +201,8 @@ Waiting for debugger to attach to app host process - [yellow]A new version of the Aspire CLI is available: {0}[/] - Do not translate [yellow] and also leave [/] as-is. {0} is the version number + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + Do not translate [yellow] and also leave [/] as-is. {0} is the version number, {1} is the update command [dim]For more information, see: [link]{0}[/][/] diff --git a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.cs.xlf b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.cs.xlf index b9392611ebb..0da95f4b5ef 100644 --- a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.cs.xlf +++ b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.cs.xlf @@ -78,9 +78,9 @@ Do not translate [dim] and [link]. Also leave [/] as-is. {0} is a URL - [yellow]A new version of the Aspire CLI is available: {0}[/] - [yellow]K dispozici je nová verze rozhraní příkazového řádku Aspire: {0}[/] - Do not translate [yellow] and also leave [/] as-is. {0} is the version number + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + Do not translate [yellow] and also leave [/] as-is. {0} is the version number, {1} is the update command No items available for selection: {0} diff --git a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.de.xlf b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.de.xlf index cabbf21608a..4adff1e1d2d 100644 --- a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.de.xlf +++ b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.de.xlf @@ -78,9 +78,9 @@ Do not translate [dim] and [link]. Also leave [/] as-is. {0} is a URL - [yellow]A new version of the Aspire CLI is available: {0}[/] - [yellow]Eine neue Version der Aspire-CLI ist verfügbar: {0}[/] - Do not translate [yellow] and also leave [/] as-is. {0} is the version number + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + Do not translate [yellow] and also leave [/] as-is. {0} is the version number, {1} is the update command No items available for selection: {0} diff --git a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.es.xlf b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.es.xlf index 67c25c40013..3e7f86e6fe4 100644 --- a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.es.xlf +++ b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.es.xlf @@ -78,9 +78,9 @@ Do not translate [dim] and [link]. Also leave [/] as-is. {0} is a URL - [yellow]A new version of the Aspire CLI is available: {0}[/] - [yellow]Hay una nueva versión disponible de la CLI de Aspire: {0}[/] - Do not translate [yellow] and also leave [/] as-is. {0} is the version number + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + Do not translate [yellow] and also leave [/] as-is. {0} is the version number, {1} is the update command No items available for selection: {0} diff --git a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.fr.xlf b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.fr.xlf index b5019ce86b4..a2bdd8d5ac1 100644 --- a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.fr.xlf +++ b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.fr.xlf @@ -78,9 +78,9 @@ Do not translate [dim] and [link]. Also leave [/] as-is. {0} is a URL - [yellow]A new version of the Aspire CLI is available: {0}[/] - [jaune]Une nouvelle version de l’interface CLI Aspire est disponible : {0}[/] - Do not translate [yellow] and also leave [/] as-is. {0} is the version number + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + Do not translate [yellow] and also leave [/] as-is. {0} is the version number, {1} is the update command No items available for selection: {0} diff --git a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.it.xlf b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.it.xlf index 287d02de9eb..7afdb00ac20 100644 --- a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.it.xlf +++ b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.it.xlf @@ -78,9 +78,9 @@ Do not translate [dim] and [link]. Also leave [/] as-is. {0} is a URL - [yellow]A new version of the Aspire CLI is available: {0}[/] - [yellow]È disponibile una nuova versione dell'interfaccia della riga di comando di Aspire: {0}[/] - Do not translate [yellow] and also leave [/] as-is. {0} is the version number + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + Do not translate [yellow] and also leave [/] as-is. {0} is the version number, {1} is the update command No items available for selection: {0} diff --git a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.ja.xlf b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.ja.xlf index 0987dd0d29d..054cf9f680a 100644 --- a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.ja.xlf +++ b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.ja.xlf @@ -78,9 +78,9 @@ Do not translate [dim] and [link]. Also leave [/] as-is. {0} is a URL - [yellow]A new version of the Aspire CLI is available: {0}[/] - [黄色]Aspire CLI の新しいバージョンが利用可能です: {0}[/] - Do not translate [yellow] and also leave [/] as-is. {0} is the version number + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + Do not translate [yellow] and also leave [/] as-is. {0} is the version number, {1} is the update command No items available for selection: {0} diff --git a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.ko.xlf b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.ko.xlf index 1cf27893c44..bd6fe643b18 100644 --- a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.ko.xlf +++ b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.ko.xlf @@ -78,9 +78,9 @@ Do not translate [dim] and [link]. Also leave [/] as-is. {0} is a URL - [yellow]A new version of the Aspire CLI is available: {0}[/] - [yellow]새 버전의 Aspire CLI {0}[/]을(를) 사용할 수 있습니다. - Do not translate [yellow] and also leave [/] as-is. {0} is the version number + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + Do not translate [yellow] and also leave [/] as-is. {0} is the version number, {1} is the update command No items available for selection: {0} diff --git a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.pl.xlf b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.pl.xlf index 96e907c278a..6c3264e270e 100644 --- a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.pl.xlf +++ b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.pl.xlf @@ -78,9 +78,9 @@ Do not translate [dim] and [link]. Also leave [/] as-is. {0} is a URL - [yellow]A new version of the Aspire CLI is available: {0}[/] - [yellow]Dostępna jest nowa wersja interfejsu wiersza polecenia Aspire: {0}[/] - Do not translate [yellow] and also leave [/] as-is. {0} is the version number + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + Do not translate [yellow] and also leave [/] as-is. {0} is the version number, {1} is the update command No items available for selection: {0} diff --git a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.pt-BR.xlf b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.pt-BR.xlf index 446fd104ee6..7b86284ae89 100644 --- a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.pt-BR.xlf +++ b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.pt-BR.xlf @@ -78,9 +78,9 @@ Do not translate [dim] and [link]. Also leave [/] as-is. {0} is a URL - [yellow]A new version of the Aspire CLI is available: {0}[/] - [yellow]Uma nova versão da CLI do Aspire está disponível: {0}[/] - Do not translate [yellow] and also leave [/] as-is. {0} is the version number + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + Do not translate [yellow] and also leave [/] as-is. {0} is the version number, {1} is the update command No items available for selection: {0} diff --git a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.ru.xlf b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.ru.xlf index 686c7cd4c10..bc8271fde09 100644 --- a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.ru.xlf +++ b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.ru.xlf @@ -78,9 +78,9 @@ Do not translate [dim] and [link]. Also leave [/] as-is. {0} is a URL - [yellow]A new version of the Aspire CLI is available: {0}[/] - [yellow]Доступна новая версия Aspire CLI: {0}[/] - Do not translate [yellow] and also leave [/] as-is. {0} is the version number + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + Do not translate [yellow] and also leave [/] as-is. {0} is the version number, {1} is the update command No items available for selection: {0} diff --git a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.tr.xlf b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.tr.xlf index 7c641303d64..7e39e4f567e 100644 --- a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.tr.xlf +++ b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.tr.xlf @@ -78,9 +78,9 @@ Do not translate [dim] and [link]. Also leave [/] as-is. {0} is a URL - [yellow]A new version of the Aspire CLI is available: {0}[/] - [yellow]Aspire CLI'nin yeni bir sürümü kullanılabilir: {0}[/] - Do not translate [yellow] and also leave [/] as-is. {0} is the version number + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + Do not translate [yellow] and also leave [/] as-is. {0} is the version number, {1} is the update command No items available for selection: {0} diff --git a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.zh-Hans.xlf b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.zh-Hans.xlf index 1b04a2e41ef..e44bb891756 100644 --- a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.zh-Hans.xlf +++ b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.zh-Hans.xlf @@ -78,9 +78,9 @@ Do not translate [dim] and [link]. Also leave [/] as-is. {0} is a URL - [yellow]A new version of the Aspire CLI is available: {0}[/] - [yellow]有新版本的 Aspire CLI 可用: {0}[/] - Do not translate [yellow] and also leave [/] as-is. {0} is the version number + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + Do not translate [yellow] and also leave [/] as-is. {0} is the version number, {1} is the update command No items available for selection: {0} diff --git a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.zh-Hant.xlf b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.zh-Hant.xlf index 4cdef524be3..781d716a680 100644 --- a/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.zh-Hant.xlf +++ b/src/Aspire.Cli/Resources/xlf/InteractionServiceStrings.zh-Hant.xlf @@ -78,9 +78,9 @@ Do not translate [dim] and [link]. Also leave [/] as-is. {0} is a URL - [yellow]A new version of the Aspire CLI is available: {0}[/] - [yellow]有新版的 Aspire CLI 可供使用: {0}[/] - Do not translate [yellow] and also leave [/] as-is. {0} is the version number + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + [yellow]A new version of the Aspire CLI is available: {0}. Use {1} to update.[/] + Do not translate [yellow] and also leave [/] as-is. {0} is the version number, {1} is the update command No items available for selection: {0} diff --git a/tests/Aspire.Cli.Tests/Interaction/ConsoleInteractionServiceTests.cs b/tests/Aspire.Cli.Tests/Interaction/ConsoleInteractionServiceTests.cs index 2a0257a0256..a62f002f555 100644 --- a/tests/Aspire.Cli.Tests/Interaction/ConsoleInteractionServiceTests.cs +++ b/tests/Aspire.Cli.Tests/Interaction/ConsoleInteractionServiceTests.cs @@ -280,4 +280,33 @@ public async Task ConfirmAsync_WhenInteractiveInputNotSupported_ThrowsInvalidOpe interactionService.ConfirmAsync("Confirm?", true, CancellationToken.None)); Assert.Contains(InteractionServiceStrings.InteractiveInputNotSupported, exception.Message); } + + [Fact] + public void DisplayVersionUpdateNotification_IncludesUpdateCommand() + { + // Arrange + var output = new StringBuilder(); + var console = AnsiConsole.Create(new AnsiConsoleSettings + { + Ansi = AnsiSupport.No, + ColorSystem = ColorSystemSupport.NoColors, + Out = new AnsiConsoleOutput(new StringWriter(output)) + }); + + var executionContext = new CliExecutionContext(new DirectoryInfo("."), new DirectoryInfo("."), new DirectoryInfo("."), new DirectoryInfo(Path.Combine(Path.GetTempPath(), "aspire-test-runtimes"))); + var interactionService = new ConsoleInteractionService(console, executionContext, TestHelpers.CreateInteractiveHostEnvironment()); + var version = "13.0.0-preview.1.25526.1"; + + // Act + interactionService.DisplayVersionUpdateNotification(version); + + // Assert + var outputString = output.ToString(); + Assert.Contains(version, outputString); + // The message should include an update command (either "aspire update --self" or "dotnet tool update aspire.cli") + Assert.True( + outputString.Contains("aspire update --self") || outputString.Contains("dotnet tool update aspire.cli"), + "Output should contain an update command"); + Assert.Contains("https://aka.ms/aspire/update", outputString); + } } From 0d4c347e3d1f61e851b7cf09b0607e74d63789ef Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Oct 2025 16:00:38 +0000 Subject: [PATCH 3/3] Centralize IsRunningAsDotNetTool logic in CliHostEnvironment Move duplicate IsRunningAsDotNetTool method from UpdateCommand and ConsoleInteractionService to a shared static method in CliHostEnvironment. This reduces code duplication and provides a single source of truth for detecting whether the CLI is running as a dotnet tool or native binary. Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com> --- src/Aspire.Cli/Commands/UpdateCommand.cs | 16 +-------------- .../Interaction/ConsoleInteractionService.cs | 16 +-------------- src/Aspire.Cli/Utils/CliHostEnvironment.cs | 20 +++++++++++++++++++ 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/src/Aspire.Cli/Commands/UpdateCommand.cs b/src/Aspire.Cli/Commands/UpdateCommand.cs index f3272a04476..097623b10e0 100644 --- a/src/Aspire.Cli/Commands/UpdateCommand.cs +++ b/src/Aspire.Cli/Commands/UpdateCommand.cs @@ -53,7 +53,7 @@ public UpdateCommand( Options.Add(projectOption); // Only add --self option if not running as dotnet tool - if (!IsRunningAsDotNetTool()) + if (!CliHostEnvironment.IsRunningAsDotNetTool()) { var selfOption = new Option("--self"); selfOption.Description = "Update the Aspire CLI itself to the latest version"; @@ -67,20 +67,6 @@ public UpdateCommand( protected override bool UpdateNotificationsEnabled => false; - private static bool IsRunningAsDotNetTool() - { - // When running as a dotnet tool, the process path points to "dotnet" or "dotnet.exe" - // When running as a native binary, it points to "aspire" or "aspire.exe" - var processPath = Environment.ProcessPath; - if (string.IsNullOrEmpty(processPath)) - { - return false; - } - - var fileName = Path.GetFileNameWithoutExtension(processPath); - return string.Equals(fileName, "dotnet", StringComparison.OrdinalIgnoreCase); - } - protected override async Task ExecuteAsync(ParseResult parseResult, CancellationToken cancellationToken) { var isSelfUpdate = parseResult.GetValue("--self"); diff --git a/src/Aspire.Cli/Interaction/ConsoleInteractionService.cs b/src/Aspire.Cli/Interaction/ConsoleInteractionService.cs index 2221e168b74..0fe7d8b48c1 100644 --- a/src/Aspire.Cli/Interaction/ConsoleInteractionService.cs +++ b/src/Aspire.Cli/Interaction/ConsoleInteractionService.cs @@ -248,25 +248,11 @@ public void DisplayVersionUpdateNotification(string newerVersion) _ansiConsole.WriteLine(); // Determine the update command based on how the CLI is running - var updateCommand = IsRunningAsDotNetTool() + var updateCommand = CliHostEnvironment.IsRunningAsDotNetTool() ? "dotnet tool update aspire.cli" : "aspire update --self"; _ansiConsole.MarkupLine(string.Format(CultureInfo.CurrentCulture, InteractionServiceStrings.NewCliVersionAvailable, newerVersion, updateCommand)); _ansiConsole.MarkupLine(string.Format(CultureInfo.CurrentCulture, InteractionServiceStrings.MoreInfoNewCliVersion, UpdateUrl)); } - - private static bool IsRunningAsDotNetTool() - { - // When running as a dotnet tool, the process path points to "dotnet" or "dotnet.exe" - // When running as a native binary, it points to "aspire" or "aspire.exe" - var processPath = Environment.ProcessPath; - if (string.IsNullOrEmpty(processPath)) - { - return false; - } - - var fileName = Path.GetFileNameWithoutExtension(processPath); - return string.Equals(fileName, "dotnet", StringComparison.OrdinalIgnoreCase); - } } diff --git a/src/Aspire.Cli/Utils/CliHostEnvironment.cs b/src/Aspire.Cli/Utils/CliHostEnvironment.cs index 5f6a3f3e4b0..0bb0ffef036 100644 --- a/src/Aspire.Cli/Utils/CliHostEnvironment.cs +++ b/src/Aspire.Cli/Utils/CliHostEnvironment.cs @@ -154,4 +154,24 @@ private static bool IsCI(IConfiguration configuration) return false; } + + /// + /// Determines whether the CLI is running as a dotnet tool. + /// + /// + /// true if the CLI is running as a dotnet tool; otherwise, false if running as a native binary. + /// + public static bool IsRunningAsDotNetTool() + { + // When running as a dotnet tool, the process path points to "dotnet" or "dotnet.exe" + // When running as a native binary, it points to "aspire" or "aspire.exe" + var processPath = Environment.ProcessPath; + if (string.IsNullOrEmpty(processPath)) + { + return false; + } + + var fileName = Path.GetFileNameWithoutExtension(processPath); + return string.Equals(fileName, "dotnet", StringComparison.OrdinalIgnoreCase); + } }