Skip to content
Draft
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
60 changes: 32 additions & 28 deletions src/Cli/dotnet/Commands/CliCommandStrings.resx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
Microsoft ResX Schema

Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple

There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -2609,6 +2609,10 @@ To display a value, specify the corresponding command-line option without provid
<value>Tool package {0}@{1} will be downloaded from source {2}.
Proceed?</value>
</data>
<data name="ToolDownloadPackageNotFoundButHasPrerelease" xml:space="preserve">
<value>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.</value>
</data>
<comment>{Locked="--prerelease"}</comment>
<data name="ConfirmationPromptYesValue" xml:space="preserve">
<value>y</value>
<comment>For a command line connfirmation prompt, this is the key that should be pressed for "yes", ie to agree.</comment>
Expand Down Expand Up @@ -2698,4 +2702,4 @@ Proceed?</value>
<value>Received 'ExecutionId' of value '{0}' for message '{1}' while the 'ExecutionId' received of the handshake message was '{2}'.</value>
<comment>{Locked="ExecutionId"}</comment>
</data>
</root>
</root>
100 changes: 65 additions & 35 deletions src/Cli/dotnet/Commands/Tool/Execute/ToolExecuteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

/// <summary>
/// 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.
/// </summary>
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)
Expand Down
10 changes: 4 additions & 6 deletions src/Cli/dotnet/Commands/Tool/Install/ParseResultExtension.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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 + "]");
}
Expand Down
5 changes: 5 additions & 0 deletions src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading