Skip to content

[Feature]: Verifying the package source mapping configuration #11959

Open
@a-ctor

Description

@a-ctor

NuGet Product(s) Involved

NuGet.exe, dotnet.exe

The Elevator Pitch

With the new package source mapping it is possible to restrict certain packages to be restored from specific package sources. But there are scenarios with package source mapping where a local restore succeeds but fails on another machine. This happens when the packages are already cached locally and so the package source mapping is not considered when restoring. This is quite annoying when verifying the package source mapping as the Nuget package cache must be cleared to test a new configuration.

I propose adding an option that will check that all the required packages can be resolved from the package sources using the current package source mapping (skipping the local cache of course). The exact details are up for discussion.

Looking forward for you input on the matter :)

Additional Context and Details

Here is a step-by-step example of how to replicate the problem. Only after clearing the cache does it become clear that the package source mapping does not work.

  1. dotnet new classlib -n test -o .
  2. dotnet add test.csproj package NUnit: Install any package which is automatically restored and cached
  3. Add a Nuget.config which filters out the installed package using <packageSourceMapping> (see example below)
  4. dotnet restore: Does not fail because the package is cached
  5. Remove %USERPROFILE%\.nuget\packages\NUnit: Remove the package from the cache
  6. dotnet restore: Restore fails because the package source mapping must be used

Here is an example Nuget.config with a restrictive filter:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
  <packageSourceMapping>
    <packageSource key="nuget.org">
      <package pattern="Does not match the package" />
    </packageSource>
  </packageSourceMapping>
</configuration>

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions