Skip to content

Commit 2da7939

Browse files
authored
Manually port fix 50027 to the 10.0.1xx branch (#50966)
2 parents d69a91d + 7a41eab commit 2da7939

17 files changed

+171
-3
lines changed

src/Cli/dotnet/CliStrings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,4 +838,7 @@ The default is 'false.' However, when targeting .NET 7 or lower, the default is
838838
<data name="PackCmd_OneNuspecAllowed" xml:space="preserve">
839839
<value>Only one .nuspec file can be packed at a time</value>
840840
</data>
841+
<data name="Error_NU1302_HttpSourceUsed" xml:space="preserve">
842+
<value>You are running the 'tool install' operation with an 'HTTP' source: {0}. NuGet requires HTTPS sources. To use an HTTP source, you must explicitly set 'allowInsecureConnections' to true in your NuGet.Config file. Refer to https://aka.ms/nuget-https-everywhere for more information.</value>
843+
</data>
841844
</root>

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,22 @@ public ToolInstallGlobalOrToolPathCommand(
9696
NoCache: parseResult.GetValue(ToolCommandRestorePassThroughOptions.NoCacheOption) || parseResult.GetValue(ToolCommandRestorePassThroughOptions.NoHttpCacheOption),
9797
IgnoreFailedSources: parseResult.GetValue(ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption),
9898
Interactive: parseResult.GetValue(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption));
99-
nugetPackageDownloader ??= new NuGetPackageDownloader.NuGetPackageDownloader(tempDir, verboseLogger: new NullLogger(), restoreActionConfig: restoreActionConfig, verbosityOptions: _verbosity, verifySignatures: verifySignatures ?? true);
99+
nugetPackageDownloader ??= new NuGetPackageDownloader.NuGetPackageDownloader(tempDir, verboseLogger: new NullLogger(), restoreActionConfig: restoreActionConfig, verbosityOptions: _verbosity, verifySignatures: verifySignatures ?? true, shouldUsePackageSourceMapping: true, currentWorkingDirectory: _currentWorkingDirectory);
100+
101+
// Perform HTTP source validation early to ensure compatibility with .NET 9 requirements
102+
if (_packageId != null)
103+
{
104+
var packageSourceLocationForValidation = new PackageSourceLocation(
105+
nugetConfig: GetConfigFile(),
106+
additionalSourceFeeds: _addSource,
107+
basePath: _currentWorkingDirectory);
108+
109+
if (nugetPackageDownloader is NuGetPackageDownloader.NuGetPackageDownloader concreteDownloader)
110+
{
111+
concreteDownloader.LoadNuGetSources((PackageId)_packageId, packageSourceLocationForValidation);
112+
}
113+
}
114+
100115
_shellShimTemplateFinder = new ShellShimTemplateFinder(nugetPackageDownloader, tempDir, packageSourceLocation);
101116
_store = store;
102117

src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
#nullable disable
55

66
using System.Collections.Concurrent;
7+
using Microsoft.DotNet.Cli.Extensions;
78
using Microsoft.DotNet.Cli.NugetPackageDownloader;
89
using Microsoft.DotNet.Cli.ToolPackage;
910
using Microsoft.DotNet.Cli.Utils;
11+
using Microsoft.DotNet.Cli.Utils.Extensions;
1012
using Microsoft.Extensions.EnvironmentAbstractions;
1113
using NuGet.Common;
1214
using NuGet.Configuration;
@@ -450,9 +452,21 @@ public IEnumerable<PackageSource> LoadNuGetSources(PackageId packageId, PackageS
450452
throw new NuGetPackageInstallerException("No NuGet sources are defined or enabled");
451453
}
452454

455+
CheckHttpSources(sources);
453456
return sources;
454457
}
455458

459+
private void CheckHttpSources(IEnumerable<PackageSource> packageSources)
460+
{
461+
foreach (var packageSource in packageSources)
462+
{
463+
if (packageSource.IsHttp && !packageSource.IsHttps && !packageSource.AllowInsecureConnections)
464+
{
465+
throw new NuGetPackageInstallerException(string.Format(CliStrings.Error_NU1302_HttpSourceUsed, packageSource.Source));
466+
}
467+
}
468+
}
469+
456470
private async Task<(PackageSource, IPackageSearchMetadata)> GetMatchingVersionInternalAsync(
457471
string packageIdentifier, IEnumerable<PackageSource> packageSources, VersionRange versionRange,
458472
CancellationToken cancellationToken)

src/Cli/dotnet/xlf/CliStrings.cs.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/xlf/CliStrings.de.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/xlf/CliStrings.es.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/xlf/CliStrings.fr.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/xlf/CliStrings.it.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/xlf/CliStrings.ja.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/xlf/CliStrings.ko.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)