diff --git a/src/Cli/dotnet/CliStrings.resx b/src/Cli/dotnet/CliStrings.resx index e84f13ad8021..9852b3e8cb5c 100644 --- a/src/Cli/dotnet/CliStrings.resx +++ b/src/Cli/dotnet/CliStrings.resx @@ -455,6 +455,9 @@ setx PATH "%PATH%;{0}" {0}: failed to find toolAssembly for {1} + + 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 + Failed to load NuGet source {0} diff --git a/src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs b/src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs index a0ce16fe6d0b..cdba7ea6f87e 100644 --- a/src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs +++ b/src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs @@ -371,6 +371,25 @@ private IEnumerable LoadOverrideSources(PackageSourceLocation pac } + private void ValidateSourceMappingCompatibility(PackageSourceLocation sourceLocation, PackageSourceMapping mapping) + { + // When mapping feature is active and user specified extra feeds via CLI, this creates a conflict + // because the extra feeds won't be in the mapping configuration + if (mapping?.IsEnabled != true) + { + return; + } + + var extraFeeds = sourceLocation?.AdditionalSourceFeed; + if (extraFeeds == null || extraFeeds.Length == 0) + { + return; + } + + // Found both mapping and CLI-added feeds - this combination won't work + throw new NuGetPackageInstallerException(CliStrings.CannotUseAddSourceWithSourceMapping); + } + private List LoadDefaultSources(PackageId packageId, PackageSourceLocation packageSourceLocation = null, PackageSourceMapping packageSourceMapping = null) { List defaultSources = []; @@ -395,6 +414,12 @@ private List LoadDefaultSources(PackageId packageId, PackageSourc packageSourceMapping ??= PackageSourceMapping.GetPackageSourceMapping(settings); + // Ensure compatibility between source mapping configuration and CLI options + if (_shouldUsePackageSourceMapping) + { + ValidateSourceMappingCompatibility(packageSourceLocation, packageSourceMapping); + } + // filter package patterns if enabled if (_shouldUsePackageSourceMapping && packageSourceMapping?.IsEnabled == true) { diff --git a/src/Cli/dotnet/xlf/CliStrings.cs.xlf b/src/Cli/dotnet/xlf/CliStrings.cs.xlf index 389c5822431c..db5371f22682 100644 --- a/src/Cli/dotnet/xlf/CliStrings.cs.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.cs.xlf @@ -59,6 +59,11 @@ Zadání možností -r|--runtime a -os zároveň se nepodporuje. + + 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 + 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 + + Column maximum width must be greater than zero. Maximální šířka sloupce musí být větší než nula. diff --git a/src/Cli/dotnet/xlf/CliStrings.de.xlf b/src/Cli/dotnet/xlf/CliStrings.de.xlf index b1249c1c91e0..ddea45d9cfb0 100644 --- a/src/Cli/dotnet/xlf/CliStrings.de.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.de.xlf @@ -59,6 +59,11 @@ Das gleichzeitige Angeben der Optionen „-r|--runtime“ und „-os“ wird nicht unterstützt. + + 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 + 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 + + Column maximum width must be greater than zero. Die maximale Spaltenbreite muss größer als 0 sein. diff --git a/src/Cli/dotnet/xlf/CliStrings.es.xlf b/src/Cli/dotnet/xlf/CliStrings.es.xlf index c2a7f96f8839..2e66a832a734 100644 --- a/src/Cli/dotnet/xlf/CliStrings.es.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.es.xlf @@ -59,6 +59,11 @@ No se admite la especificación de las opciones '-r|--runtime' y '-os'. + + 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 + 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 + + Column maximum width must be greater than zero. El ancho máximo de la columna debe ser superior a cero. diff --git a/src/Cli/dotnet/xlf/CliStrings.fr.xlf b/src/Cli/dotnet/xlf/CliStrings.fr.xlf index eeff65e8e1e0..b3cd285e60fc 100644 --- a/src/Cli/dotnet/xlf/CliStrings.fr.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.fr.xlf @@ -59,6 +59,11 @@ La spécification des options « -r |--Runtime » et « os » n’est pas prise en charge. + + 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 + 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 + + Column maximum width must be greater than zero. La largeur maximale de colonne doit être supérieure à zéro. diff --git a/src/Cli/dotnet/xlf/CliStrings.it.xlf b/src/Cli/dotnet/xlf/CliStrings.it.xlf index 206d295fe385..6b4798b5e654 100644 --- a/src/Cli/dotnet/xlf/CliStrings.it.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.it.xlf @@ -59,6 +59,11 @@ La specifica di entrambe le opzioni `-r|--runtime` e `-os` non è supportata. + + 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 + 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 + + Column maximum width must be greater than zero. La larghezza massima della colonna deve essere maggiore di zero. diff --git a/src/Cli/dotnet/xlf/CliStrings.ja.xlf b/src/Cli/dotnet/xlf/CliStrings.ja.xlf index 4a8b5dd083ad..de6ce5eb5e0d 100644 --- a/src/Cli/dotnet/xlf/CliStrings.ja.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.ja.xlf @@ -59,6 +59,11 @@ `-r|--runtime` および `-os` オプションの両方を指定することはサポートされていません。 + + 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 + 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 + + Column maximum width must be greater than zero. 列の最大幅はゼロより大きくなければなりません。 diff --git a/src/Cli/dotnet/xlf/CliStrings.ko.xlf b/src/Cli/dotnet/xlf/CliStrings.ko.xlf index 069408145055..8e2a8fd5cbe0 100644 --- a/src/Cli/dotnet/xlf/CliStrings.ko.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.ko.xlf @@ -59,6 +59,11 @@ `-r|--runtime` 및 `-os` 옵션을 모두 지정하는 것은 지원되지 않습니다. + + 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 + 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 + + Column maximum width must be greater than zero. 열 최대 너비는 0보다 커야 합니다. diff --git a/src/Cli/dotnet/xlf/CliStrings.pl.xlf b/src/Cli/dotnet/xlf/CliStrings.pl.xlf index 09cf70e51f97..ecdf18a4ef35 100644 --- a/src/Cli/dotnet/xlf/CliStrings.pl.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.pl.xlf @@ -59,6 +59,11 @@ Określanie opcji „-r|--runtime” i „-os” nie jest obsługiwane. + + 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 + 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 + + Column maximum width must be greater than zero. Maksymalna szerokość kolumny musi być większa niż zero. diff --git a/src/Cli/dotnet/xlf/CliStrings.pt-BR.xlf b/src/Cli/dotnet/xlf/CliStrings.pt-BR.xlf index f92a5e258743..953da0a993eb 100644 --- a/src/Cli/dotnet/xlf/CliStrings.pt-BR.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.pt-BR.xlf @@ -59,6 +59,11 @@ Não há suporte para especificar as opções '-r |--runtime ' e '-a |--os '. + + 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 + 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 + + Column maximum width must be greater than zero. A largura máxima da coluna deve ser maior que zero. diff --git a/src/Cli/dotnet/xlf/CliStrings.ru.xlf b/src/Cli/dotnet/xlf/CliStrings.ru.xlf index a45ec9415519..a0d9c87fb26a 100644 --- a/src/Cli/dotnet/xlf/CliStrings.ru.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.ru.xlf @@ -59,6 +59,11 @@ Указание параметров "-r|--runtime" и "-os" не поддерживается. + + 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 + 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 + + Column maximum width must be greater than zero. Максимальная ширина столбца должна быть больше нуля. diff --git a/src/Cli/dotnet/xlf/CliStrings.tr.xlf b/src/Cli/dotnet/xlf/CliStrings.tr.xlf index b139a21005e6..b69a06287572 100644 --- a/src/Cli/dotnet/xlf/CliStrings.tr.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.tr.xlf @@ -59,6 +59,11 @@ Hem `-r|--runtime` hem de `-os` seçeneğinin belirtilmesi desteklenmiyor. + + 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 + 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 + + Column maximum width must be greater than zero. Maksimum sütun genişliği sıfırdan büyük olmalıdır. diff --git a/src/Cli/dotnet/xlf/CliStrings.zh-Hans.xlf b/src/Cli/dotnet/xlf/CliStrings.zh-Hans.xlf index 28f1e78422ac..bb50e59dfae7 100644 --- a/src/Cli/dotnet/xlf/CliStrings.zh-Hans.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.zh-Hans.xlf @@ -59,6 +59,11 @@ 不支持同时指定“-r |--runtime”和“-os”选项。 + + 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 + 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 + + Column maximum width must be greater than zero. 列的最大宽度必须大于零。 diff --git a/src/Cli/dotnet/xlf/CliStrings.zh-Hant.xlf b/src/Cli/dotnet/xlf/CliStrings.zh-Hant.xlf index 59521667921e..f8f638292eac 100644 --- a/src/Cli/dotnet/xlf/CliStrings.zh-Hant.xlf +++ b/src/Cli/dotnet/xlf/CliStrings.zh-Hant.xlf @@ -59,6 +59,11 @@ 不支援同時指定 `-r|--runtime` 與 `-os` 選項。 + + 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 + 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 + + Column maximum width must be greater than zero. 資料行寬度上限必須大於零。 diff --git a/test/Microsoft.DotNet.PackageInstall.Tests/NuGetPackageInstallerTests.cs b/test/Microsoft.DotNet.PackageInstall.Tests/NuGetPackageInstallerTests.cs index 8e0693efdad9..a23dac5004c2 100644 --- a/test/Microsoft.DotNet.PackageInstall.Tests/NuGetPackageInstallerTests.cs +++ b/test/Microsoft.DotNet.PackageInstall.Tests/NuGetPackageInstallerTests.cs @@ -174,43 +174,59 @@ public async Task GivenARelativeSourcePathInstallSucceeds() [Fact] public async Task GivenNoPackageSourceMappingItShouldError() { - string getTestLocalFeedPath = GetTestLocalFeedPath(); - string relativePath = Path.GetRelativePath(Environment.CurrentDirectory, getTestLocalFeedPath); - Log.WriteLine(relativePath); - var dictionary = new Dictionary> - { - { "sourceA", new List() { "a" } } - }; - var patterns = new ReadOnlyDictionary>(dictionary); - var mockPackageSourceMapping = new PackageSourceMapping(patterns); + string testFeed = GetTestLocalFeedPath(); + FilePath configPath = GenerateRandomNugetConfigFilePath(); + FileSystemWrapper fs = new(); + + fs.Directory.CreateDirectory(configPath.GetDirectoryPath().Value); + string configContent = $@" + + + + + + + + + + +"; + fs.File.WriteAllText(configPath.Value, configContent); - Func a = () => _toolInstaller.DownloadPackageAsync( + Func downloadAction = () => _toolInstaller.DownloadPackageAsync( TestPackageId, new NuGetVersion(TestPackageVersion), - new PackageSourceLocation(additionalSourceFeeds: [ relativePath ]), - packageSourceMapping: mockPackageSourceMapping); - (await a.Should().ThrowAsync()).And.Message.Should().Contain(string.Format(CliStrings.FailedToFindSourceUnderPackageSourceMapping, TestPackageId)); + new PackageSourceLocation(nugetConfig: configPath)); + (await downloadAction.Should().ThrowAsync()).And.Message.Should().Contain(string.Format(CliStrings.FailedToFindSourceUnderPackageSourceMapping, TestPackageId)); } [Fact] public async Task GivenPackageSourceMappingFeedNotFoundItShouldError() { - string getTestLocalFeedPath = GetTestLocalFeedPath(); - string relativePath = Path.GetRelativePath(Environment.CurrentDirectory, getTestLocalFeedPath); - Log.WriteLine(relativePath); - var dictionary = new Dictionary> - { - { "nonexistentfeed", new List() { TestPackageId.ToString() } } - }; - var patterns = new ReadOnlyDictionary>(dictionary); - var mockPackageSourceMapping = new PackageSourceMapping(patterns); + string testFeed = GetTestLocalFeedPath(); + FilePath configPath = GenerateRandomNugetConfigFilePath(); + FileSystemWrapper fs = new(); + + fs.Directory.CreateDirectory(configPath.GetDirectoryPath().Value); + string configContent = $@" + + + + + + + + + + +"; + fs.File.WriteAllText(configPath.Value, configContent); - Func a = () => _toolInstaller.DownloadPackageAsync( + Func downloadAction = () => _toolInstaller.DownloadPackageAsync( TestPackageId, new NuGetVersion(TestPackageVersion), - new PackageSourceLocation(additionalSourceFeeds: [ relativePath ]), - packageSourceMapping: mockPackageSourceMapping); - (await a.Should().ThrowAsync()).And.Message.Should().Contain(string.Format(CliStrings.FailedToMapSourceUnderPackageSourceMapping, TestPackageId)); + new PackageSourceLocation(nugetConfig: configPath)); + (await downloadAction.Should().ThrowAsync()).And.Message.Should().Contain(string.Format(CliStrings.FailedToMapSourceUnderPackageSourceMapping, TestPackageId)); } [Fact] @@ -391,5 +407,25 @@ private static FilePath GenerateRandomNugetConfigFilePath() private static string GetTestLocalFeedPath() => Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestAssetLocalNugetFeed"); + + [Fact] + public async Task RejectsAdditionalSourceFeedsWhenMappingActive() + { + var mappingRules = new Dictionary> + { + { "feed1", new List { "PackageX.*" } } + }; + var mapping = new PackageSourceMapping(new ReadOnlyDictionary>(mappingRules)); + string someFeed = GetTestLocalFeedPath(); + + var download = () => _toolInstaller.DownloadPackageAsync( + TestPackageId, + new NuGetVersion(TestPackageVersion), + new PackageSourceLocation(additionalSourceFeeds: new[] { someFeed }), + packageSourceMapping: mapping); + + (await download.Should().ThrowAsync()) + .Which.Message.Should().Contain(CliStrings.CannotUseAddSourceWithSourceMapping); + } } }