Skip to content

Commit 031a03c

Browse files
committed
PR feedback
1 parent 0ce1599 commit 031a03c

File tree

6 files changed

+112
-52
lines changed

6 files changed

+112
-52
lines changed

src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,25 @@ private IEnumerable<PackageSource> LoadNuGetSources(PackageSourceLocation packag
319319
PackageSourceProvider packageSourceProvider = new PackageSourceProvider(settings);
320320
defaultSources = packageSourceProvider.LoadPackageSources().Where(source => source.IsEnabled);
321321

322+
foreach (string source in packageSourceLocation?.AdditionalSourceFeed)
323+
{
324+
if (string.IsNullOrWhiteSpace(source))
325+
{
326+
continue;
327+
}
328+
329+
PackageSource packageSource = new PackageSource(source);
330+
if (packageSource.TrySourceAsUri == null)
331+
{
332+
_verboseLogger.LogWarning(string.Format(
333+
LocalizableStrings.FailedToLoadNuGetSource,
334+
source));
335+
continue;
336+
}
337+
338+
defaultSources = defaultSources.Append(packageSource);
339+
}
340+
322341
if (!packageSourceLocation?.SourceFeedOverrides.Any() ?? true)
323342
{
324343
if (!defaultSources.Any())

src/Cli/dotnet/NugetPackageDownloader/PackageSourceLocation.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System;
5-
using System.Collections.Generic;
65
using System.IO;
76
using Microsoft.Extensions.EnvironmentAbstractions;
87

@@ -13,18 +12,21 @@ internal class PackageSourceLocation
1312
public PackageSourceLocation(
1413
FilePath? nugetConfig = null,
1514
DirectoryPath? rootConfigDirectory = null,
16-
string[] sourceFeedOverrides = null)
15+
string[] sourceFeedOverrides = null,
16+
string[] additionalSourceFeeds = null)
1717
{
1818
NugetConfig = nugetConfig;
1919
RootConfigDirectory = rootConfigDirectory;
20-
ExpandLocalFeedAndAssign(sourceFeedOverrides);
20+
SourceFeedOverrides = ExpandLocalFeed(sourceFeedOverrides);
21+
AdditionalSourceFeed = ExpandLocalFeed(additionalSourceFeeds);
2122
}
2223

2324
public FilePath? NugetConfig { get; }
2425
public DirectoryPath? RootConfigDirectory { get; }
2526
public string[] SourceFeedOverrides { get; private set; }
27+
public string[] AdditionalSourceFeed { get; private set; }
2628

27-
private void ExpandLocalFeedAndAssign(string[] sourceFeedOverrides)
29+
private string[] ExpandLocalFeed(string[] sourceFeedOverrides)
2830
{
2931
if (sourceFeedOverrides != null)
3032
{
@@ -42,11 +44,11 @@ private void ExpandLocalFeedAndAssign(string[] sourceFeedOverrides)
4244
}
4345
}
4446

45-
SourceFeedOverrides = localFeedsThatIsRooted;
47+
return localFeedsThatIsRooted;
4648
}
4749
else
4850
{
49-
SourceFeedOverrides = Array.Empty<string>();
51+
return Array.Empty<string>();
5052
}
5153
}
5254
}

src/Cli/dotnet/ShellShim/ShellShimRepository.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Collections.Generic;
66
using System.IO;
77
using System.Linq;
8-
using System.Runtime.InteropServices;
98
using Microsoft.DotNet.Cli;
109
using Microsoft.DotNet.Cli.Utils;
1110
using Microsoft.DotNet.Tools;
@@ -15,8 +14,6 @@ namespace Microsoft.DotNet.ShellShim
1514
{
1615
internal class ShellShimRepository : IShellShimRepository
1716
{
18-
private const string ApphostNameWithoutExtension = "apphost";
19-
2017
private readonly DirectoryPath _shimsDirectory;
2118
private readonly IFileSystem _fileSystem;
2219
private readonly IAppHostShellShimMaker _appHostShellShimMaker;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.IO;
6+
using System.Linq;
7+
using System.Runtime.InteropServices;
8+
using System.Threading.Tasks;
9+
using Microsoft.DotNet.Cli;
10+
using Microsoft.DotNet.Cli.NuGetPackageDownloader;
11+
using Microsoft.DotNet.Cli.Utils;
12+
using Microsoft.DotNet.ToolPackage;
13+
using Microsoft.Extensions.EnvironmentAbstractions;
14+
using NuGet.Frameworks;
15+
using LocalizableStrings = Microsoft.DotNet.Tools.Tool.Install.LocalizableStrings;
16+
17+
namespace Microsoft.DotNet.ShellShim
18+
{
19+
internal class ShellShimTemplateFinder
20+
{
21+
private readonly DirectoryPath _tempDir;
22+
private readonly INuGetPackageDownloader _nugetPackageDownloader;
23+
private readonly PackageSourceLocation _packageSourceLocation;
24+
25+
public ShellShimTemplateFinder(
26+
INuGetPackageDownloader nugetPackageDownloader,
27+
DirectoryPath tempDir,
28+
PackageSourceLocation packageSourceLocation)
29+
{
30+
_tempDir = tempDir;
31+
_nugetPackageDownloader = nugetPackageDownloader;
32+
_packageSourceLocation = packageSourceLocation;
33+
}
34+
35+
public async Task<string> ResolveAppHostSourceDirectoryAsync(string archOption, string targetFramework)
36+
{
37+
string rid;
38+
var validRids = new string[] { "win-x64", "win-arm64", "osx-x64", "osx-arm64" };
39+
if (string.IsNullOrEmpty(archOption))
40+
{
41+
if (!string.IsNullOrEmpty(targetFramework) && new NuGetFramework(targetFramework).Version < new Version("6.0")
42+
&& (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) && !RuntimeInformation.ProcessArchitecture.Equals(Architecture.X64))
43+
{
44+
rid = OperatingSystem.IsWindows() ? "win-x64" : "osx-x64";
45+
}
46+
else
47+
{
48+
// Use the default app host
49+
return null;
50+
}
51+
}
52+
else
53+
{
54+
rid = CommonOptions.ResolveRidShorthandOptionsToRuntimeIdentifier(null, archOption);
55+
}
56+
57+
if (!validRids.Contains(rid))
58+
{
59+
throw new GracefulException(string.Format(LocalizableStrings.InvalidRuntimeIdentifier, rid, string.Join(" ", validRids)));
60+
}
61+
62+
var packageId = new PackageId($"microsoft.netcore.app.host.{rid}");
63+
var packagePath = await _nugetPackageDownloader.DownloadPackageAsync(packageId, packageSourceLocation: _packageSourceLocation);
64+
var content = await _nugetPackageDownloader.ExtractPackageAsync(packagePath, _tempDir);
65+
66+
return Path.Combine(_tempDir.Value, "runtimes", rid, "native");
67+
}
68+
}
69+
}

src/Cli/dotnet/commands/dotnet-tool/ToolCommandRestorePassThroughOptions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ namespace Microsoft.DotNet.Cli
1111
{
1212
internal static class ToolCommandRestorePassThroughOptions
1313
{
14-
public static Option DisableParallelOption = new ForwardedOption<bool>(
14+
public static Option<bool> DisableParallelOption = new ForwardedOption<bool>(
1515
"--disable-parallel",
1616
LocalizableStrings.CmdDisableParallelOptionDescription)
1717
.ForwardAs("--disable-parallel");
1818

19-
public static Option NoCacheOption = new ForwardedOption<bool>(
19+
public static Option<bool> NoCacheOption = new ForwardedOption<bool>(
2020
"--no-cache",
2121
LocalizableStrings.CmdNoCacheOptionDescription)
2222
.ForwardAs("--no-cache");
2323

24-
public static Option IgnoreFailedSourcesOption = new ForwardedOption<bool>(
24+
public static Option<bool> IgnoreFailedSourcesOption = new ForwardedOption<bool>(
2525
"--ignore-failed-sources",
2626
LocalizableStrings.CmdIgnoreFailedSourcesOptionDescription)
2727
.ForwardAs("--ignore-failed-sources");
2828

29-
public static Option InteractiveRestoreOption = new ForwardedOption<bool>(
29+
public static Option<bool> InteractiveRestoreOption = new ForwardedOption<bool>(
3030
"--interactive",
3131
CommonLocalizableStrings.CommandInteractiveOptionDescription)
3232
.ForwardAs(Constants.RestoreInteractiveOption);

src/Cli/dotnet/commands/dotnet-tool/install/ToolInstallGlobalOrToolPathCommand.cs

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ internal class ToolInstallGlobalOrToolPathCommand : CommandBase
3434
private readonly IReporter _errorReporter;
3535
private CreateShellShimRepository _createShellShimRepository;
3636
private CreateToolPackageStoresAndInstaller _createToolPackageStoresAndInstaller;
37+
private readonly ShellShimTemplateFinder _shellShimTemplateFinder;
3738

3839
private readonly PackageId _packageId;
3940
private readonly string _packageVersion;
@@ -45,8 +46,6 @@ internal class ToolInstallGlobalOrToolPathCommand : CommandBase
4546
private readonly string _toolPath;
4647
private readonly string _architectureOption;
4748
private IEnumerable<string> _forwardRestoreArguments;
48-
private readonly DirectoryPath _tempDir;
49-
private readonly INuGetPackageDownloader _nugetPackageDownloader;
5049

5150
public ToolInstallGlobalOrToolPathCommand(
5251
ParseResult parseResult,
@@ -73,8 +72,16 @@ public ToolInstallGlobalOrToolPathCommand(
7372
_environmentPathInstruction = environmentPathInstruction
7473
?? EnvironmentPathFactory.CreateEnvironmentPathInstruction();
7574
_createShellShimRepository = createShellShimRepository ?? ShellShimRepositoryFactory.CreateShellShimRepository;
76-
_tempDir = new DirectoryPath(Path.Combine(Path.GetTempPath(), "dotnet-tool-install"));
77-
_nugetPackageDownloader = nugetPackageDownloader ?? new NuGetPackageDownloader(_tempDir, verboseLogger: new NullLogger());
75+
var tempDir = new DirectoryPath(Path.Combine(Path.GetTempPath(), "dotnet-tool-install"));
76+
var configOption = parseResult.ValueForOption(ToolInstallCommandParser.ConfigOption);
77+
var sourceOption = parseResult.ValueForOption(ToolInstallCommandParser.AddSourceOption);
78+
var packageSourceLocation = new PackageSourceLocation(string.IsNullOrEmpty(configOption) ? null : new FilePath(configOption), additionalSourceFeeds: sourceOption);
79+
var restoreAction = new RestoreActionConfig(DisableParallel: parseResult.ValueForOption(ToolCommandRestorePassThroughOptions.DisableParallelOption),
80+
NoCache: parseResult.ValueForOption(ToolCommandRestorePassThroughOptions.NoCacheOption),
81+
IgnoreFailedSources: parseResult.ValueForOption(ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption),
82+
Interactive: parseResult.ValueForOption(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption));
83+
nugetPackageDownloader ??= new NuGetPackageDownloader(tempDir, verboseLogger: new NullLogger(), restoreActionConfig: restoreAction);
84+
_shellShimTemplateFinder = new ShellShimTemplateFinder(nugetPackageDownloader, tempDir, packageSourceLocation);
7885

7986
_reporter = (reporter ?? Reporter.Output);
8087
_errorReporter = (reporter ?? Reporter.Error);
@@ -105,7 +112,7 @@ public override int Execute()
105112
toolPath = new DirectoryPath(_toolPath);
106113
}
107114

108-
string appHostSourceDirectory = ResolveAppHostSourceDirectoryAsync(_architectureOption, _framework).Result;
115+
string appHostSourceDirectory = _shellShimTemplateFinder.ResolveAppHostSourceDirectoryAsync(_architectureOption, _framework).Result;
109116

110117
(IToolPackageStore toolPackageStore, IToolPackageStoreQuery toolPackageStoreQuery, IToolPackageInstaller toolPackageInstaller) =
111118
_createToolPackageStoresAndInstaller(toolPath, _forwardRestoreArguments);
@@ -171,39 +178,5 @@ public override int Execute()
171178
isUserError: false);
172179
}
173180
}
174-
175-
private async Task<string> ResolveAppHostSourceDirectoryAsync(string archOption, string targetFramework)
176-
{
177-
string rid;
178-
var validRids = new string[] { "win-x64", "win-arm64", "osx-x64", "osx-arm64" };
179-
if (string.IsNullOrEmpty(archOption))
180-
{
181-
if (!string.IsNullOrEmpty(targetFramework) && new NuGetFramework(targetFramework).Version < new Version("6.0")
182-
&& (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) && !RuntimeInformation.ProcessArchitecture.Equals(Architecture.X64))
183-
{
184-
rid = OperatingSystem.IsWindows() ? "win-x64" : "osx-x64";
185-
}
186-
else
187-
{
188-
// Use the default app host
189-
return null;
190-
}
191-
}
192-
else
193-
{
194-
rid = CommonOptions.ResolveRidShorthandOptionsToRuntimeIdentifier(null, archOption);
195-
}
196-
197-
if (!validRids.Contains(rid))
198-
{
199-
throw new GracefulException(string.Format(LocalizableStrings.InvalidRuntimeIdentifier, rid, string.Join(" ", validRids)));
200-
}
201-
202-
var packageId = new PackageId($"microsoft.netcore.app.host.{rid}");
203-
var packagePath = await _nugetPackageDownloader.DownloadPackageAsync(packageId);
204-
var content = await _nugetPackageDownloader.ExtractPackageAsync(packagePath, _tempDir);
205-
206-
return Path.Combine(_tempDir.Value, "runtimes", rid, "native");
207-
}
208181
}
209182
}

0 commit comments

Comments
 (0)