Skip to content

Commit 4d104f1

Browse files
authored
Reject --add-source when package source mapping is enabled (#52863)
2 parents a5af8d7 + 43fdca5 commit 4d104f1

16 files changed

+155
-26
lines changed

src/Cli/dotnet/CliStrings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,9 @@ setx PATH "%PATH%;{0}"
455455
<data name="FailedToFindToolAssembly" xml:space="preserve">
456456
<value>{0}: failed to find toolAssembly for {1}</value>
457457
</data>
458+
<data name="CannotUseAddSourceWithSourceMapping" xml:space="preserve">
459+
<value>The --add-source option cannot be combined with package source mapping. To use an additional source, update your NuGet configuration file's source mapping settings. Learn more: https://aka.ms/nuget-package-source-mapping</value>
460+
</data>
458461
<data name="FailedToLoadNuGetSource" xml:space="preserve">
459462
<value>Failed to load NuGet source {0}</value>
460463
</data>

src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,25 @@ private IEnumerable<PackageSource> LoadOverrideSources(PackageSourceLocation pac
371371

372372
}
373373

374+
private void ValidateSourceMappingCompatibility(PackageSourceLocation sourceLocation, PackageSourceMapping mapping)
375+
{
376+
// When mapping feature is active and user specified extra feeds via CLI, this creates a conflict
377+
// because the extra feeds won't be in the mapping configuration
378+
if (mapping?.IsEnabled != true)
379+
{
380+
return;
381+
}
382+
383+
var extraFeeds = sourceLocation?.AdditionalSourceFeed;
384+
if (extraFeeds == null || extraFeeds.Length == 0)
385+
{
386+
return;
387+
}
388+
389+
// Found both mapping and CLI-added feeds - this combination won't work
390+
throw new NuGetPackageInstallerException(CliStrings.CannotUseAddSourceWithSourceMapping);
391+
}
392+
374393
private List<PackageSource> LoadDefaultSources(PackageId packageId, PackageSourceLocation packageSourceLocation = null, PackageSourceMapping packageSourceMapping = null)
375394
{
376395
List<PackageSource> defaultSources = [];
@@ -395,6 +414,12 @@ private List<PackageSource> LoadDefaultSources(PackageId packageId, PackageSourc
395414

396415
packageSourceMapping ??= PackageSourceMapping.GetPackageSourceMapping(settings);
397416

417+
// Ensure compatibility between source mapping configuration and CLI options
418+
if (_shouldUsePackageSourceMapping)
419+
{
420+
ValidateSourceMappingCompatibility(packageSourceLocation, packageSourceMapping);
421+
}
422+
398423
// filter package patterns if enabled
399424
if (_shouldUsePackageSourceMapping && packageSourceMapping?.IsEnabled == true)
400425
{

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.

src/Cli/dotnet/xlf/CliStrings.pl.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)