Skip to content

Commit 47d0bba

Browse files
authored
Support RID-specific .NET Tool packages (#48575)
2 parents 9309351 + ce1bba1 commit 47d0bba

File tree

127 files changed

+3625
-1926
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+3625
-1926
lines changed

eng/dogfood.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ try {
4747

4848
$env:PATH = "$TestDotnetRoot;$env:Path"
4949
$env:DOTNET_ROOT = $TestDotnetRoot
50+
$env:DOTNET_ADD_GLOBAL_TOOLS_TO_PATH="0"
5051

5152
# Avoid downloading Microsoft.Net.Sdk.Compilers.Toolset from feed
5253
# Locally built SDK package version is Major.Minor.0-dev, which won't be available.

eng/dogfood.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ export MicrosoftNETBuildExtensionsTargets="$artifacts_dir/bin/$configuration/Sdk
2525

2626
export PATH=$testDotnetRoot:$PATH
2727
export DOTNET_ROOT=$testDotnetRoot
28+
export DOTNET_ADD_GLOBAL_TOOLS_TO_PATH=0
2829
export PS1="(dogfood) $PS1"

eng/restore-toolset.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ set DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR=$env:DOTNET_INSTALL_DIR
5151
5252
set PATH=$env:DOTNET_INSTALL_DIR;%PATH%
5353
set NUGET_PACKAGES=$env:NUGET_PACKAGES
54+
set DOTNET_ADD_GLOBAL_TOOLS_TO_PATH=0
5455
5556
DOSKEY killdotnet=taskkill /F /IM dotnet.exe /T ^& taskkill /F /IM VSTest.Console.exe /T ^& taskkill /F /IM msbuild.exe /T
5657
"@
@@ -70,6 +71,7 @@ DOSKEY killdotnet=taskkill /F /IM dotnet.exe /T ^& taskkill /F /IM VSTest.Consol
7071
7172
`$env:PATH="$env:DOTNET_INSTALL_DIR;" + `$env:PATH
7273
`$env:NUGET_PACKAGES="$env:NUGET_PACKAGES"
74+
`$env:DOTNET_ADD_GLOBAL_TOOLS_TO_PATH="0"
7375
7476
function killdotnet {
7577
taskkill /F /IM dotnet.exe /T

eng/restore-toolset.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR=$DOTNET_INSTALL_DIR
6161
6262
export PATH=$DOTNET_INSTALL_DIR:\$PATH
6363
export NUGET_PACKAGES=$NUGET_PACKAGES
64+
export DOTNET_ADD_GLOBAL_TOOLS_TO_PATH=0
6465
"
6566

6667
echo "$scriptContents" > ${scriptPath}

src/Cli/dotnet/CliStrings.resx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@
319319
<data name="ToolSettingsUnsupportedRunner" xml:space="preserve">
320320
<value>Command '{0}' uses unsupported runner '{1}'."</value>
321321
</data>
322+
<data name="ToolUnsupportedRuntimeIdentifier" xml:space="preserve">
323+
<value>The tool does not support the current architecture or operating system ({0}). Supported runtimes: {1}</value>
324+
</data>
322325
<data name="ShellShimConflict" xml:space="preserve">
323326
<value>Command '{0}' conflicts with an existing command from another tool.</value>
324327
</data>
@@ -413,6 +416,9 @@ setx PATH "%PATH%;{0}"
413416
<data name="ToolPackageConflictPackageId" xml:space="preserve">
414417
<value>Tool '{0}' (version '{1}') is already installed.</value>
415418
</data>
419+
<data name="ToolPackageNotATool" xml:space="preserve">
420+
<value>Package {0} is not a .NET tool.</value>
421+
</data>
416422
<data name="FailedToFindStagedToolPackage" xml:space="preserve">
417423
<value>Failed to find staged tool package '{0}'.</value>
418424
</data>
@@ -435,7 +441,10 @@ setx PATH "%PATH%;{0}"
435441
<value>More than one packaged shim is available: {0}.</value>
436442
</data>
437443
<data name="FailedToReadNuGetLockFile" xml:space="preserve">
438-
<value>Failed to read NuGet LockFile for tool package '{0}': {1}</value>
444+
<value>Failed to read NuGet assets file for tool package '{0}': {1}</value>
445+
</data>
446+
<data name="FailedToFindLibraryInAssetsFile" xml:space="preserve">
447+
<value>Failed to find library in NuGet assets file for tool package '{0}': {1}</value>
439448
</data>
440449
<data name="LevelArgumentName" xml:space="preserve">
441450
<value>LEVEL</value>

src/Cli/dotnet/CommandFactory/CommandResolution/LocalToolsCommandResolver.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.DotNet.Cli.ToolPackage;
88
using Microsoft.DotNet.Cli.Utils;
99
using Microsoft.Extensions.EnvironmentAbstractions;
10+
using NuGet.DependencyResolver;
1011
using NuGet.Frameworks;
1112

1213
namespace Microsoft.DotNet.Cli.CommandFactory.CommandResolution;
@@ -82,22 +83,39 @@ private CommandSpec GetPackageCommandSpecUsingMuxer(CommandResolverArguments arg
8283
NuGetFramework.Parse(BundledTargetFramework.GetTargetFrameworkMoniker()),
8384
Constants.AnyRid,
8485
toolCommandName),
85-
out var restoredCommand))
86+
out var toolCommand))
8687
{
87-
if (!_fileSystem.File.Exists(restoredCommand.Executable.Value))
88+
if (!_fileSystem.File.Exists(toolCommand.Executable.Value))
8889
{
8990
throw new GracefulException(string.Format(CliStrings.NeedRunToolRestore,
9091
toolCommandName.ToString()));
9192
}
9293

93-
if (toolManifestPackage.RollForward || allowRollForward)
94+
if (toolCommand.Runner == "dotnet")
9495
{
95-
arguments.CommandArguments = ["--allow-roll-forward", .. arguments.CommandArguments];
96+
if (toolManifestPackage.RollForward || allowRollForward)
97+
{
98+
arguments.CommandArguments = ["--allow-roll-forward", .. arguments.CommandArguments];
99+
}
100+
101+
return MuxerCommandSpecMaker.CreatePackageCommandSpecUsingMuxer(
102+
toolCommand.Executable.Value,
103+
arguments.CommandArguments);
96104
}
105+
else if (toolCommand.Runner == "executable")
106+
{
107+
var escapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(
108+
arguments.CommandArguments);
97109

98-
return MuxerCommandSpecMaker.CreatePackageCommandSpecUsingMuxer(
99-
restoredCommand.Executable.Value,
100-
arguments.CommandArguments);
110+
return new CommandSpec(
111+
toolCommand.Executable.Value,
112+
escapedArgs);
113+
}
114+
else
115+
{
116+
throw new GracefulException(string.Format(CliStrings.ToolSettingsUnsupportedRunner,
117+
toolCommand.Name, toolCommand.Runner));
118+
}
101119
}
102120
else
103121
{

src/Cli/dotnet/Commands/CliCommandStrings.resx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,16 +1938,6 @@ Your project targets multiple frameworks. Specify which framework to run using '
19381938
<data name="ToolInstallationFailedContactAuthor" xml:space="preserve">
19391939
<value>Tool '{0}' failed to install. Contact the tool author for assistance.</value>
19401940
</data>
1941-
<data name="ToolInstallationFailedWithRestoreGuidance" xml:space="preserve">
1942-
<value>Tool '{0}' failed to install. This failure may have been caused by:
1943-
1944-
* You are attempting to install a preview release and did not use the --version option to specify the version.
1945-
* A package by this name was found, but it was not a .NET tool.
1946-
* The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
1947-
* You mistyped the name of the tool.
1948-
1949-
For more reasons, including package naming enforcement, visit https://aka.ms/failure-installing-tool</value>
1950-
</data>
19511941
<data name="ToolInstallationRestoreFailed" xml:space="preserve">
19521942
<value>The tool package could not be restored.</value>
19531943
</data>
@@ -2486,4 +2476,4 @@ To display a value, specify the corresponding command-line option without provid
24862476
<data name="SolutionAddReferencedProjectsOptionDescription" xml:space="preserve">
24872477
<value>Recursively add projects' ReferencedProjects to solution</value>
24882478
</data>
2489-
</root>
2479+
</root>

src/Cli/dotnet/Commands/Pack/PackCommandParser.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ private static Command ConstructCommand()
8484
command.Options.Add(CommonOptions.VersionSuffixOption);
8585
command.Options.Add(ConfigurationOption);
8686
command.Options.Add(CommonOptions.DisableBuildServersOption);
87-
RestoreCommandParser.AddImplicitRestoreOptions(command, includeRuntimeOption: true, includeNoDependenciesOption: true);
87+
88+
// Don't include runtime option because we want to include it specifically and allow the short version ("-r") to be used
89+
RestoreCommandParser.AddImplicitRestoreOptions(command, includeRuntimeOption: false, includeNoDependenciesOption: true);
90+
command.Options.Add(CommonOptions.RuntimeOption(CliCommandStrings.BuildRuntimeOptionDescription));
8891

8992
command.SetAction(PackCommand.Run);
9093

src/Cli/dotnet/Commands/Tool/Install/LocalToolsResolverCacheExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static void SaveToolPackage(
3333
}
3434

3535
localToolsResolverCache.Save(
36-
new Dictionary<RestoredCommandIdentifier, RestoredCommand>
36+
new Dictionary<RestoredCommandIdentifier, ToolCommand>
3737
{
3838
[new RestoredCommandIdentifier(
3939
toolDownloadedPackage.Id,

src/Cli/dotnet/Commands/Tool/Install/ToolInstallCommandLowLevelErrorConverter.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ internal static class InstallToolCommandLowLevelErrorConverter
1212
{
1313
public static IEnumerable<string> GetUserFacingMessages(Exception ex, PackageId packageId)
1414
{
15-
if (ex is ToolPackageException)
16-
{
17-
yield return ex.Message;
18-
yield return string.Format(CliCommandStrings.ToolInstallationFailedWithRestoreGuidance, packageId);
19-
}
20-
else if (ex is ToolConfigurationException)
15+
if (ex is ToolConfigurationException)
2116
{
2217
yield return string.Format(CliCommandStrings.InvalidToolConfiguration, ex.Message);
2318
yield return string.Format(CliCommandStrings.ToolInstallationFailedContactAuthor, packageId);
@@ -31,8 +26,7 @@ public static IEnumerable<string> GetUserFacingMessages(Exception ex, PackageId
3126

3227
public static bool ShouldConvertToUserFacingError(Exception ex)
3328
{
34-
return ex is ToolPackageException
35-
|| ex is ToolConfigurationException
29+
return ex is ToolConfigurationException
3630
|| ex is ShellShimException;
3731
}
3832
}

0 commit comments

Comments
 (0)