Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automatically tool upgrade and downgrade for versions for dotnet tool local install #35080

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,7 @@ If you would like to create a manifest, use `dotnet new tool-manifest`, usually
<data name="PrereleaseAndVersionAreNotSupportedAtTheSameTime" xml:space="preserve">
<value>The --prerelease and --version options are not supported in the same command</value>
</data>
<data name="AllowPackageDowngradeOptionDescription" xml:space="preserve">
<value>Allow package downgrade when installing a .NET tool package.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ internal static class ToolInstallCommandParser
ArgumentHelpName = LocalizableStrings.FrameworkOptionName
};

public static readonly Option<bool> AllowPackageDowngradeOption = new Option<bool>("--allow-downgrade", LocalizableStrings.AllowPackageDowngradeOptionDescription);

public static readonly Option<bool> PrereleaseOption = ToolSearchCommandParser.PrereleaseOption;

public static readonly Option<VerbosityOptions> VerbosityOption = CommonOptions.VerbosityOption;
Expand Down Expand Up @@ -80,6 +82,7 @@ private static Command ConstructCommand()
command.AddOption(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption);
command.AddOption(VerbosityOption);
command.AddOption(ArchitectureOption);
command.AddOption(AllowPackageDowngradeOption);

command.SetHandler((parseResult) => new ToolInstallCommand(parseResult).Execute());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.DotNet.ToolPackage;
using Microsoft.DotNet.Tools.Tool.Common;
using Microsoft.Extensions.EnvironmentAbstractions;
using NuGet.Packaging;

namespace Microsoft.DotNet.Tools.Tool.Install
{
Expand All @@ -21,6 +22,8 @@ internal class ToolInstallLocalCommand : CommandBase
private readonly ILocalToolsResolverCache _localToolsResolverCache;
private readonly ToolInstallLocalInstaller _toolLocalPackageInstaller;
private readonly IReporter _reporter;
private readonly PackageId _packageId;
private readonly bool _allowPackageDowngrade;

private readonly string _explicitManifestFile;

Expand All @@ -42,16 +45,87 @@ public ToolInstallLocalCommand(
_toolManifestEditor = toolManifestEditor ?? new ToolManifestEditor();
_localToolsResolverCache = localToolsResolverCache ?? new LocalToolsResolverCache();
_toolLocalPackageInstaller = new ToolInstallLocalInstaller(parseResult, toolPackageInstaller);
_allowPackageDowngrade = parseResult.GetValue(ToolInstallCommandParser.AllowPackageDowngradeOption);
_packageId = new PackageId(parseResult.GetValue(ToolUpdateCommandParser.PackageIdArgument));
}

public override int Execute()
{
FilePath manifestFile = GetManifestFilePath();
(FilePath? manifestFileOptional, string warningMessage) =
_toolManifestFinder.ExplicitManifestOrFindManifestContainPackageId(_explicitManifestFile, _packageId);

return Install(manifestFile);
if (warningMessage != null)
{
_reporter.WriteLine(warningMessage.Yellow());
}

var manifestFile = manifestFileOptional ?? GetManifestFilePath();
var existingPackageWithPackageId = _toolManifestFinder.Find(manifestFile).Where(p => p.PackageId.Equals(_packageId));

if (!existingPackageWithPackageId.Any())
{
return InstallNewTool(manifestFile);
}

var existingPackage = existingPackageWithPackageId.Single();
var toolDownloadedPackage = _toolLocalPackageInstaller.Install(manifestFile);

InstallToolUpdate(existingPackage, toolDownloadedPackage, manifestFile);

_localToolsResolverCache.SaveToolPackage(
toolDownloadedPackage,
_toolLocalPackageInstaller.TargetFrameworkToInstall);

return 0;
}

public int InstallToolUpdate(ToolManifestPackage existingPackage, IToolPackage toolDownloadedPackage, FilePath manifestFile)
{
if (existingPackage.Version > toolDownloadedPackage.Version && !_allowPackageDowngrade)
{
throw new GracefulException(new[]
{
string.Format(
Update.LocalizableStrings.UpdateLocalToolToLowerVersion,
toolDownloadedPackage.Version.ToNormalizedString(),
existingPackage.Version.ToNormalizedString(),
manifestFile.Value)
},
isUserError: false);
}
else if (existingPackage.Version == toolDownloadedPackage.Version)
{
_reporter.WriteLine(
string.Format(
Update.LocalizableStrings.UpdateLocaToolSucceededVersionNoChange,
toolDownloadedPackage.Id,
existingPackage.Version.ToNormalizedString(),
manifestFile.Value));
}
else
{
_toolManifestEditor.Edit(
manifestFile,
_packageId,
toolDownloadedPackage.Version,
toolDownloadedPackage.Commands.Select(c => c.Name).ToArray());
_reporter.WriteLine(
string.Format(
Update.LocalizableStrings.UpdateLocalToolSucceeded,
toolDownloadedPackage.Id,
existingPackage.Version.ToNormalizedString(),
toolDownloadedPackage.Version.ToNormalizedString(),
manifestFile.Value).Green());
}

_localToolsResolverCache.SaveToolPackage(
toolDownloadedPackage,
_toolLocalPackageInstaller.TargetFrameworkToInstall);

return 0;
}

public int Install(FilePath manifestFile)
public int InstallNewTool(FilePath manifestFile)
{
IToolPackage toolDownloadedPackage =
_toolLocalPackageInstaller.Install(manifestFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="cs" original="../LocalizableStrings.resx">
<body>
<trans-unit id="AllowPackageDowngradeOptionDescription">
<source>Allow package downgrade when installing a .NET tool package.</source>
<target state="new">Allow package downgrade when installing a .NET tool package.</target>
<note />
</trans-unit>
<trans-unit id="InstallToolCommandInvalidGlobalAndLocalAndToolPath">
<source>The local option(--local), the global option (--global), the tool path option (--tool-path), can only have one at a time. Specify only one of the options: {0}.</source>
<target state="translated">Možnost local (--local), možnost global (--global), možnost tool path (--tool-path), v jednu chvíli je možné mít jen jednu. Zadejte jen jednu z možností: {0}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="de" original="../LocalizableStrings.resx">
<body>
<trans-unit id="AllowPackageDowngradeOptionDescription">
<source>Allow package downgrade when installing a .NET tool package.</source>
<target state="new">Allow package downgrade when installing a .NET tool package.</target>
<note />
</trans-unit>
<trans-unit id="InstallToolCommandInvalidGlobalAndLocalAndToolPath">
<source>The local option(--local), the global option (--global), the tool path option (--tool-path), can only have one at a time. Specify only one of the options: {0}.</source>
<target state="translated">Die lokale Option (--local), die globale Option (--global) und die Toolpfadoption (--tool-path) können nicht zusammen angegeben werden. Geben Sie nur eine der Optionen an: {0}.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="es" original="../LocalizableStrings.resx">
<body>
<trans-unit id="AllowPackageDowngradeOptionDescription">
<source>Allow package downgrade when installing a .NET tool package.</source>
<target state="new">Allow package downgrade when installing a .NET tool package.</target>
<note />
</trans-unit>
<trans-unit id="InstallToolCommandInvalidGlobalAndLocalAndToolPath">
<source>The local option(--local), the global option (--global), the tool path option (--tool-path), can only have one at a time. Specify only one of the options: {0}.</source>
<target state="translated">La opción local (--local), la opción global (--global) y la opción de ruta de acceso de herramienta (--tool-path), solo pueden estar una cada vez. Especifique solo una de las opciones: {0}.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="fr" original="../LocalizableStrings.resx">
<body>
<trans-unit id="AllowPackageDowngradeOptionDescription">
<source>Allow package downgrade when installing a .NET tool package.</source>
<target state="new">Allow package downgrade when installing a .NET tool package.</target>
<note />
</trans-unit>
<trans-unit id="InstallToolCommandInvalidGlobalAndLocalAndToolPath">
<source>The local option(--local), the global option (--global), the tool path option (--tool-path), can only have one at a time. Specify only one of the options: {0}.</source>
<target state="translated">L'option locale (--local), l'option globale (--global) et l'option de chemin d'outil (--tool-path) ne peuvent pas être utilisées simultanément. Spécifiez une seule des options : {0}.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="it" original="../LocalizableStrings.resx">
<body>
<trans-unit id="AllowPackageDowngradeOptionDescription">
<source>Allow package downgrade when installing a .NET tool package.</source>
<target state="new">Allow package downgrade when installing a .NET tool package.</target>
<note />
</trans-unit>
<trans-unit id="InstallToolCommandInvalidGlobalAndLocalAndToolPath">
<source>The local option(--local), the global option (--global), the tool path option (--tool-path), can only have one at a time. Specify only one of the options: {0}.</source>
<target state="translated">Le opzioni locale (--local), globale (--global) e del percorso dello strumento (--tool-path) non possono essere specificate contemporaneamente. Specificare una sola di queste opzioni: {0}.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ja" original="../LocalizableStrings.resx">
<body>
<trans-unit id="AllowPackageDowngradeOptionDescription">
<source>Allow package downgrade when installing a .NET tool package.</source>
<target state="new">Allow package downgrade when installing a .NET tool package.</target>
<note />
</trans-unit>
<trans-unit id="InstallToolCommandInvalidGlobalAndLocalAndToolPath">
<source>The local option(--local), the global option (--global), the tool path option (--tool-path), can only have one at a time. Specify only one of the options: {0}.</source>
<target state="translated">ローカル オプション (--local)、グローバル オプション (--global)、ツール パス オプション (--tool-path) は、一度に 1 つだけ指定できます。オプションを 1 つだけ指定します: {0}。</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ko" original="../LocalizableStrings.resx">
<body>
<trans-unit id="AllowPackageDowngradeOptionDescription">
<source>Allow package downgrade when installing a .NET tool package.</source>
<target state="new">Allow package downgrade when installing a .NET tool package.</target>
<note />
</trans-unit>
<trans-unit id="InstallToolCommandInvalidGlobalAndLocalAndToolPath">
<source>The local option(--local), the global option (--global), the tool path option (--tool-path), can only have one at a time. Specify only one of the options: {0}.</source>
<target state="translated">로컬 옵션(--local), 전역 옵션(--global), 도구 경로 옵션(--tool-path)은 한 번에 하나씩만 사용할 수 있습니다. {0} 옵션 중에서 하나만 지정하세요.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="pl" original="../LocalizableStrings.resx">
<body>
<trans-unit id="AllowPackageDowngradeOptionDescription">
<source>Allow package downgrade when installing a .NET tool package.</source>
<target state="new">Allow package downgrade when installing a .NET tool package.</target>
<note />
</trans-unit>
<trans-unit id="InstallToolCommandInvalidGlobalAndLocalAndToolPath">
<source>The local option(--local), the global option (--global), the tool path option (--tool-path), can only have one at a time. Specify only one of the options: {0}.</source>
<target state="translated">Można określić tylko jedną opcję jednocześnie: opcję lokalną (--local), opcję globalną (--global) lub opcję ścieżki do narzędzia (--tool-path). Podaj tylko jedną z opcji: {0}.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="pt-BR" original="../LocalizableStrings.resx">
<body>
<trans-unit id="AllowPackageDowngradeOptionDescription">
<source>Allow package downgrade when installing a .NET tool package.</source>
<target state="new">Allow package downgrade when installing a .NET tool package.</target>
<note />
</trans-unit>
<trans-unit id="InstallToolCommandInvalidGlobalAndLocalAndToolPath">
<source>The local option(--local), the global option (--global), the tool path option (--tool-path), can only have one at a time. Specify only one of the options: {0}.</source>
<target state="translated">As opções local (--local), global (--global) e do caminho da ferramenta (--tool-path) só podem ocorrer uma por vez. Especifique apenas uma das opções: {0}.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ru" original="../LocalizableStrings.resx">
<body>
<trans-unit id="AllowPackageDowngradeOptionDescription">
<source>Allow package downgrade when installing a .NET tool package.</source>
<target state="new">Allow package downgrade when installing a .NET tool package.</target>
<note />
</trans-unit>
<trans-unit id="InstallToolCommandInvalidGlobalAndLocalAndToolPath">
<source>The local option(--local), the global option (--global), the tool path option (--tool-path), can only have one at a time. Specify only one of the options: {0}.</source>
<target state="translated">Локальный параметр (--local), глобальный параметр (--global) и параметр пути к средству (--tool-path) можно использовать только отдельно друг от друга. Укажите только один из этих параметров: {0}.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="tr" original="../LocalizableStrings.resx">
<body>
<trans-unit id="AllowPackageDowngradeOptionDescription">
<source>Allow package downgrade when installing a .NET tool package.</source>
<target state="new">Allow package downgrade when installing a .NET tool package.</target>
<note />
</trans-unit>
<trans-unit id="InstallToolCommandInvalidGlobalAndLocalAndToolPath">
<source>The local option(--local), the global option (--global), the tool path option (--tool-path), can only have one at a time. Specify only one of the options: {0}.</source>
<target state="translated">Yerel seçeneği (--local), genel seçeneği (--global), araç yolu seçeneği (--tool-path) arasından yalnızca biri seçilebilir. Seçeneklerden yalnızca birini belirtin: {0}.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="zh-Hans" original="../LocalizableStrings.resx">
<body>
<trans-unit id="AllowPackageDowngradeOptionDescription">
<source>Allow package downgrade when installing a .NET tool package.</source>
<target state="new">Allow package downgrade when installing a .NET tool package.</target>
<note />
</trans-unit>
<trans-unit id="InstallToolCommandInvalidGlobalAndLocalAndToolPath">
<source>The local option(--local), the global option (--global), the tool path option (--tool-path), can only have one at a time. Specify only one of the options: {0}.</source>
<target state="translated">本地选项(--local)、全局选项(--global)和工具路径选项(--tool-path)一次只能有一个。请仅指定其中一个选项: {0}。</target>
Expand Down
Loading