diff --git a/src/Cli/dotnet/Commands/CliCommandStrings.resx b/src/Cli/dotnet/Commands/CliCommandStrings.resx index 3a3fab487f89..ca9de6e946f1 100644 --- a/src/Cli/dotnet/Commands/CliCommandStrings.resx +++ b/src/Cli/dotnet/Commands/CliCommandStrings.resx @@ -1,17 +1,17 @@  - @@ -2609,6 +2609,10 @@ To display a value, specify the corresponding command-line option without provid Tool package {0}@{1} will be downloaded from source {2}. Proceed? + + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + + {Locked="--prerelease"} y For a command line connfirmation prompt, this is the key that should be pressed for "yes", ie to agree. @@ -2698,4 +2702,4 @@ Proceed? Received 'ExecutionId' of value '{0}' for message '{1}' while the 'ExecutionId' received of the handshake message was '{2}'. {Locked="ExecutionId"} - \ No newline at end of file + diff --git a/src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommand.cs b/src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommand.cs index bdfdacb42d58..0e148d6068b6 100644 --- a/src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommand.cs +++ b/src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommand.cs @@ -41,7 +41,7 @@ internal class ToolExecuteCommand(ParseResult result, ToolManifestFinder? toolMa public override int Execute() { - VersionRange versionRange = _parseResult.GetVersionRange(); + VersionRange? versionRange = _parseResult.GetVersionRange(); PackageId packageId = new PackageId(_packageToolIdentityArgument.Id); // Look in local tools manifest first, but only if version is not specified @@ -81,48 +81,78 @@ public override int Execute() sourceFeedOverrides: _sources, additionalFeeds: _addSource); - (var bestVersion, var packageSource) = _toolPackageDownloader.GetNuGetVersion(packageLocation, packageId, _verbosity, versionRange, _restoreActionConfig); - - // TargetFramework is null, which means to use the current framework. Global tools can override the target framework to use (or select assets for), - // but we don't support this for local or one-shot tools. - if (!_toolPackageDownloader.TryGetDownloadedTool(packageId, bestVersion, targetFramework: null, verbosity: _verbosity, out var toolPackage)) + if (GetBestVersionAndSource(packageLocation, packageId, versionRange) is (var bestVersion, var packageSource)) { - if (!UserAgreedToRunFromSource(packageId, bestVersion, packageSource)) + // TargetFramework is null, which means to use the current framework. Global tools can override the target framework to use (or select assets for), + // but we don't support this for local or one-shot tools. + if (!_toolPackageDownloader.TryGetDownloadedTool(packageId, bestVersion, targetFramework: null, verbosity: _verbosity, out var toolPackage)) { - if (_interactive) + if (!UserAgreedToRunFromSource(packageId, bestVersion, packageSource)) { - Reporter.Error.WriteLine(CliCommandStrings.ToolDownloadCanceled.Red().Bold()); - return ERROR_CANCELLED; + if (_interactive) + { + Reporter.Error.WriteLine(CliCommandStrings.ToolDownloadCanceled.Red().Bold()); + return ERROR_CANCELLED; + } + else + { + Reporter.Error.WriteLine(CliCommandStrings.ToolDownloadNeedsConfirmation.Red().Bold()); + return 1; + } } - else - { - Reporter.Error.WriteLine(CliCommandStrings.ToolDownloadNeedsConfirmation.Red().Bold()); - return 1; - } - } - // We've already determined which source we will use and displayed that in a confirmation message to the user. - // So set the package location here to override the source feeds to just the source we already resolved to. - // This does mean that we won't work with feeds that have a primary package but where the RID-specific packages are on - // other feeds, but this is probably OK. - var downloadPackageLocation = new PackageLocation( - nugetConfig: _configFile != null ? new(_configFile) : null, - sourceFeedOverrides: [packageSource.Source], - additionalFeeds: _addSource); + // We've already determined which source we will use and displayed that in a confirmation message to the user. + // So set the package location here to override the source feeds to just the source we already resolved to. + // This does mean that we won't work with feeds that have a primary package but where the RID-specific packages are on + // other feeds, but this is probably OK. + var downloadPackageLocation = new PackageLocation( + nugetConfig: _configFile != null ? new(_configFile) : null, + sourceFeedOverrides: [packageSource.Source], + additionalFeeds: _addSource); + + toolPackage = _toolPackageDownloader.InstallPackage( + downloadPackageLocation, + packageId: packageId, + verbosity: _verbosity, + versionRange: new VersionRange(bestVersion, true, bestVersion, true), + isGlobalToolRollForward: false, + restoreActionConfig: _restoreActionConfig); + } - toolPackage = _toolPackageDownloader.InstallPackage( - downloadPackageLocation, - packageId: packageId, - verbosity: _verbosity, - versionRange: new VersionRange(bestVersion, true, bestVersion, true), - isGlobalToolRollForward: false, - restoreActionConfig: _restoreActionConfig); + var commandSpec = ToolCommandSpecCreator.CreateToolCommandSpec(toolPackage.Command.Name.Value, toolPackage.Command.Executable.Value, toolPackage.Command.Runner, _allowRollForward, _forwardArguments); + var command = CommandFactoryUsingResolver.Create(commandSpec); + var result = command.Execute(); + return result.ExitCode; + } + else + { + return 1; } - var commandSpec = ToolCommandSpecCreator.CreateToolCommandSpec(toolPackage.Command.Name.Value, toolPackage.Command.Executable.Value, toolPackage.Command.Runner, _allowRollForward, _forwardArguments); - var command = CommandFactoryUsingResolver.Create(commandSpec); - var result = command.Execute(); - return result.ExitCode; + } + + /// + /// Try to locate the package the user requested, and return the best version and the source it was found on. + /// If the package cannot be found, and the user did not specify a version, probe for prerelease versions to + /// give the user a nice message. + /// + private (NuGetVersion bestVersion, PackageSource packageSource)? GetBestVersionAndSource(PackageLocation packageLocation, PackageId packageId, VersionRange? versionRange) + { + try + { + (var bestVersion, var packageSource) = _toolPackageDownloader.GetNuGetVersion(packageLocation, packageId, _verbosity, versionRange, _restoreActionConfig); + return (bestVersion, packageSource); + } + catch (NuGetPackageNotFoundException) when (versionRange is null) + { + // if the package wasn't found and the user did an implied 'latest' (no version specified), try again with 'prerelease' support enabled + (var bestVersion, var packageSource) = _toolPackageDownloader.GetNuGetVersion(packageLocation, packageId, _verbosity, VersionRange.All, _restoreActionConfig); + if (bestVersion is not null && bestVersion.IsPrerelease) + { + Reporter.Error.WriteLine(string.Format(CliCommandStrings.ToolDownloadPackageNotFoundButHasPrerelease, packageId, bestVersion.ToString()).Yellow()); + } + return null; + } } private bool UserAgreedToRunFromSource(PackageId packageId, NuGetVersion version, PackageSource source) diff --git a/src/Cli/dotnet/Commands/Tool/Install/ParseResultExtension.cs b/src/Cli/dotnet/Commands/Tool/Install/ParseResultExtension.cs index fcb8364f76e8..04f72303008d 100644 --- a/src/Cli/dotnet/Commands/Tool/Install/ParseResultExtension.cs +++ b/src/Cli/dotnet/Commands/Tool/Install/ParseResultExtension.cs @@ -1,8 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#nullable disable - using System.CommandLine; using Microsoft.DotNet.Cli.Utils; using NuGet.Versioning; @@ -11,7 +9,7 @@ namespace Microsoft.DotNet.Cli.Commands.Tool.Install; internal static class ParseResultExtension { - public static VersionRange GetVersionRange(this ParseResult parseResult) + public static VersionRange? GetVersionRange(this ParseResult parseResult) { var packageVersionFromIdentityArgument = parseResult.GetValue(ToolInstallCommandParser.PackageIdentityArgument).VersionRange?.OriginalString; var packageVersionFromVersionOption = parseResult.GetValue(ToolInstallCommandParser.VersionOption); @@ -22,7 +20,7 @@ public static VersionRange GetVersionRange(this ParseResult parseResult) throw new GracefulException(CliStrings.PackageIdentityArgumentVersionOptionConflict); } - string packageVersion = packageVersionFromIdentityArgument ?? packageVersionFromVersionOption; + string? packageVersion = packageVersionFromIdentityArgument ?? packageVersionFromVersionOption; bool prerelease = parseResult.GetValue(ToolInstallCommandParser.PrereleaseOption); @@ -39,10 +37,10 @@ public static VersionRange GetVersionRange(this ParseResult parseResult) packageVersion = "*-*"; } - VersionRange versionRange = null; + VersionRange? versionRange = null; // accept 'bare' versions and interpret 'bare' versions as NuGet exact versions - if (!string.IsNullOrEmpty(packageVersion) && NuGetVersion.TryParse(packageVersion, out NuGetVersion version2)) + if (!string.IsNullOrEmpty(packageVersion) && NuGetVersion.TryParse(packageVersion, out NuGetVersion? version2)) { return new VersionRange(minVersion: version2, includeMinVersion: true, maxVersion: version2, includeMaxVersion: true, originalString: "[" + packageVersion + "]"); } diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf index a122873dc947..6b708e0be6a0 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf @@ -3218,6 +3218,11 @@ Chcete pokračovat? Stažení balíčku nástroje vyžaduje potvrzení. Spusťte v interaktivním režimu nebo potvrďte akci pomocí možnosti příkazového řádku --yes. {Locked="--yes"} + + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + + Executes a tool from source without permanently installing it. Spustí nástroj ze zdroje bez trvalé instalace. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf index d9da0a1e0d4b..7e6cf081b298 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf @@ -3218,6 +3218,11 @@ Vorgang fortsetzen? Der Download des Toolpakets muss bestätigt werden. Führen Sie den Vorgang im interaktiven Modus aus oder verwenden Sie zur Bestätigung die Befehlszeilenoption "--yes". {Locked="--yes"} + + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + + Executes a tool from source without permanently installing it. Führt ein Tool aus der Quelle aus, ohne es dauerhaft zu installieren. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf index 0d4fcd802d08..918fc2c6dabf 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf @@ -3218,6 +3218,11 @@ Proceed? La descarga del paquete de herramientas necesita confirmación. Ejecute en modo interactivo o use la opción de línea de comandos "--yes" para confirmar. {Locked="--yes"} + + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + + Executes a tool from source without permanently installing it. Ejecuta una herramienta desde el origen sin instalarla permanentemente. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf index 13384daa3e40..d554bbc6482b 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf @@ -3218,6 +3218,11 @@ Voulez-vous continuer ? Le téléchargement du package d’outils doit être confirmé. Exécutez en mode interactif ou utilisez l’option de ligne de commande « --yes » pour confirmer. {Locked="--yes"} + + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + + Executes a tool from source without permanently installing it. Exécute un outil à partir de la source sans l’installer définitivement. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf index ce5d46f15c15..49b5d0a7604d 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf @@ -3218,6 +3218,11 @@ Procedere? Il download del pacchetto dello strumento richiede conferma. Esegui in modalità interattiva o usa l'opzione della riga di comando "--yes" per confermare. {Locked="--yes"} + + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + + Executes a tool from source without permanently installing it. Esegue uno strumento dall'origine senza installarlo permanentemente. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf index cd98c4d622ae..0be65db859c7 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf @@ -3218,6 +3218,11 @@ Proceed? ツール パッケージのダウンロードには確認が必要です。対話モードで実行するか、"--yes" コマンド ライン オプションを使用して確認してください。 {Locked="--yes"} + + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + + Executes a tool from source without permanently installing it. ツールを永続的にインストールすることなく、ソースから実行します。 diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf index f1840d63dcf3..069eeeddc484 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf @@ -3218,6 +3218,11 @@ Proceed? 도구 패키지 다운로드를 확인해야 합니다. 대화형 모드에서 실행하거나 "--yes" 명령줄 옵션을 사용하여 확인하세요. {Locked="--yes"} + + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + + Executes a tool from source without permanently installing it. 영구적으로 설치하지 않고 원본에서 도구를 실행합니다. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf index 18f7a5dd14c4..87f02be18799 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf @@ -3218,6 +3218,11 @@ Kontynuować? Pobieranie pakietu narzędzi wymaga potwierdzenia. Uruchom w trybie interakcyjnym lub użyj opcji wiersza polecenia „--yes”, aby potwierdzić. {Locked="--yes"} + + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + + Executes a tool from source without permanently installing it. Wykonuje narzędzie ze źródła bez trwałego instalowania go. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf index 0ae92622b31a..2ba91dc08165 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf @@ -3218,6 +3218,11 @@ Continuar? O download do pacote de ferramentas precisa de confirmação. Execute no modo interativo ou use a opção de linha de comando "--yes" para confirmar. {Locked="--yes"} + + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + + Executes a tool from source without permanently installing it. Executa uma ferramenta da origem sem instalá-la permanentemente. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf index c8d7414bf34b..7532ea7e2adf 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf @@ -3218,6 +3218,11 @@ Proceed? Для скачивания пакета инструмента требуется подтверждение. Запустите в интерактивном режиме или используйте параметр командной строки "--yes" для подтверждения. {Locked="--yes"} + + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + + Executes a tool from source without permanently installing it. Выполняет инструмент из источника без его постоянной установки. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf index 662a06fd8fb0..e207bed69863 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf @@ -3218,6 +3218,11 @@ Devam edilsin mi? Araç paketinin indirilmesi için onay gerekiyor. Etkileşimli modda çalıştırın veya onaylamak için "--yes" komut satırı seçeneğini kullanın. {Locked="--yes"} + + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + + Executes a tool from source without permanently installing it. Aracı kalıcı olarak yüklemeden kaynaktan yürütür. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf index d292dec919f0..cd6aa10a7f4b 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf @@ -3218,6 +3218,11 @@ Proceed? 工具包下载需要确认。在交互模式下运行,或使用 “--yes” 命令行选项进行确认。 {Locked="--yes"} + + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + + Executes a tool from source without permanently installing it. 从源执行工具,而无需永久安装它。 diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf index 77d4e805d580..04267bf4fcba 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf @@ -3218,6 +3218,11 @@ Proceed? 工具套件下載需要確認。請以互動模式執行,或使用 "--yes" 命令列選項來確認。 {Locked="--yes"} + + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + A stable version of Tool package {0} could not be found, but a prerelease version ({1}) was found. Try re-running with the `--prerelease` option or this explicit version to run this tool. + + Executes a tool from source without permanently installing it. 從來源執行工具,但不永久性地安裝。