NuGet packageSourceMapping "no source defines the pattern" in CI
When packageSourceMapping is enabled, a package only restores from sources whose patterns match its id. If no pattern matches, NuGet refuses to look at any source and restore fails even though the package exists.
What this error means
restore fails to find a package that is clearly on a feed, because the packageSourceMapping section has no pattern covering that id, so no source is allowed to serve it.
error NU1100: Unable to resolve 'Contoso.Internal (>= 1.0.0)' for 'net8.0'.
PackageSourceMapping is enabled, the following source(s) were not considered:
private (no matching package pattern for Contoso.Internal).Common causes
No mapping pattern matches the package id
Source mapping restricts each source to declared id patterns. A package whose id matches no pattern is served by no source.
A new package added without updating the mapping
You referenced a new internal package but did not add its id (or a prefix) to the private source mapping.
How to fix it
Add a matching pattern to the source
- Identify which feed hosts the package.
- Add a
packageSourceentry with a pattern that matches the id or its prefix. - Restore again so the mapping allows that source.
<packageSourceMapping>
<packageSource key="private">
<package pattern="Contoso.*" />
</packageSource>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
</packageSourceMapping>Verify prefixes cover all internal ids
Use a prefix pattern like Contoso.* so new internal packages under that namespace resolve without editing the mapping each time.
How to prevent it
- Map private feeds with prefix patterns that cover your namespaces.
- Update
packageSourceMappingwhenever a new id namespace appears. - Keep a
*mapping to nuget.org for public packages.