Reject --add-source when package source mapping is enabled#52863
Reject --add-source when package source mapping is enabled#52863Copilot wants to merge 5 commits intorelease/10.0.3xxfrom
Conversation
- Add ValidateSourceMappingCompatibility method to check for incompatible option combination - Add CannotUseAddSourceWithSourceMapping error message - Add test RejectsAdditionalSourceFeedsWhenMappingActive Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
…e overrides Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
|
@copilot The new warning is a little wordy. Can you remove the second sentence and modify the last sentence to read "To use an additional source, update your NuGet..." |
|
Tested and it works well. Error message is too long though so asked it to shorten the message. Nobody's got time to read all that. |
Remove redundant second sentence and change "different" to "additional" Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Updated the error message as requested in commit 43fdca5. The message now reads: "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" |
There was a problem hiding this comment.
Pull request overview
This PR improves the .NET CLI’s handling of NuGet Package Source Mapping by proactively rejecting --add-source when source mapping is enabled, producing a clearer, actionable error earlier in execution.
Changes:
- Added early validation in
NuGetPackageDownloader.LoadDefaultSourcesto rejectAdditionalSourceFeedwhen package source mapping is enabled. - Introduced a new localized resource string (
CannotUseAddSourceWithSourceMapping) for a clearer error message. - Added a unit test to verify the new validation behavior.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/Microsoft.DotNet.PackageInstall.Tests/NuGetPackageInstallerTests.cs | Adds/adjusts tests to cover the new “reject --add-source with source mapping” validation path. |
| src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs | Implements early compatibility validation between package source mapping and CLI-provided additional sources. |
| src/Cli/dotnet/CliStrings.resx | Adds the new user-facing error message resource. |
| src/Cli/dotnet/xlf/CliStrings.*.xlf | Adds the new trans-unit for localization across supported languages. |
Package source mapping filters sources to only those explicitly configured for each package pattern. Adding sources via
--add-sourcebypasses this configuration, causing NuGet to fail later with unclear errors when the added source isn't in the mapping.Changes
ValidateSourceMappingCompatibilitymethod inLoadDefaultSourcesthat detects when both package source mapping is enabled andAdditionalSourceFeedis populated, throwing immediately before NuGet operationsCannotUseAddSourceWithSourceMappingresource string directing users to update their NuGet.config insteadRejectsAdditionalSourceFeedsWhenMappingActivetest verifying the validation triggers correctlyExample
Before this change, users would see confusing NuGet errors:
After this change:
Note:
--source(which replaces all sources) remains compatible with package source mapping.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.