Skip to content

[BUG]: DotNetCoreCLI@2 breaks package source mappings for internal feeds when using a nuget.config file #21507

@cdavis-elekta

Description

@cdavis-elekta

New issue checklist

Task name

DotNetCoreCLI

Task version

2

Issue Description

The DotNetCoreCLI task's restore command prepends feed- to a package source key for each private (internal) feed it discovers in a nuget.config file stored in the source repo (i.e., when the nugetConfigPath task input is set) but DOES NOT prepend feed- to the same key in a package source mapping element, effectively breaking package source mapping.

I have replaced the actual private feed information with example in the nuget.config file shown below and the logs.

<configuration>
  <packageSources>
    <clear/>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json"/>
    <add key="example" value="https://pkgs.dev.azure.com/Example/project/_packaging/example/nuget/v3/index.json"/>
  </packageSources>
  <packageSourceMapping>
    <packageSource key="nuget.org">
      <package pattern="*"/>
    </packageSource>
    <packageSource key="example">
      <package pattern="Example.*"/>
    </packageSource>
  </packageSourceMapping>
</configuration>
`

This results in "Package source mapping match not found for package ID 'Example.Package'" errors and can result in restore failures

To work around this bug, I had to prepend `feed-` to the package source element with the key `example` in the nuget.config in the source repository, as follows:

```xml
<configuration>
  <packageSources>
    <clear/>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json"/>
    <add key="example" value="https://pkgs.dev.azure.com/Example/project/_packaging/example/nuget/v3/index.json"/>
  </packageSources>
  <packageSourceMapping>
    <packageSource key="nuget.org">
      <package pattern="*"/>
    </packageSource>
    <packageSource key="feed-example">
      <package pattern="Example.*"/>
    </packageSource>
  </packageSourceMapping>
</configuration>
`

### Environment type (Please select at least one enviroment where you face this issue)

- [ ] Self-Hosted
- [x] Microsoft Hosted
- [ ] VMSS Pool
- [ ] Container

### Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

### Azure DevOps Server Version (if applicable)

N/A

### Operation system

N/A

### Relevant log output

```shell
Output extracted from dotnet restore run by the task with `verbosityRestore: Detailed` task input:

Restoring packages for .NETCoreApp,Version=v8.0...
         Package source mapping match not found for package ID 'Example.Package'.
         Package source mapping matches found for package ID 'Microsoft.NET.Test.Sdk' are: 'nuget.org'.

Full task logs with system.debug enabled

##[debug]Setting up sources ##[debug]selectOrConfig=config ##[debug]nugetConfigPath=/__w/6/s/src/nuget.config ##[debug]check path : /__w/6/s/src/nuget.config ##[debug]nugetConfigPath=/__w/6/s/src/nuget.config ##[debug]Absolute path for pathSegments: /__w/6/s/src/nuget.config = /__w/6/s/src/nuget.config ##[debug]build.sourcesDirectory=/__w/6/s ##[debug]Absolute path for pathSegments: /__w/6/s = /__w/6/s ##[debug]nugetConfigPathpath supplied :true ##[debug]Agent.BuildDirectory=/__w/6 ##[debug]build.buildId=1000000 ##[debug]Setting auth in the temp nuget.config ##[debug]Saving NuGet.config to a temporary config file. ##[debug]Getting sources from NuGet.config in this location: /__w/6/Nuget/tempNuGet_1004187.config ##[debug]considering source https://api.nuget.org/v3/index.json. Internal: false ##[debug]No external auth information ##[debug]considering source https://pkgs.dev.azure.com/Example/project/_packaging/example/nuget/v3/index.json. Internal: true ##[debug]Setting auth for internal source https://pkgs.dev.azure.com/Example/project/_packaging/example/nuget/v3/index.json ##[debug]Prefixing internal source feed name example with feed- ##[debug]ValidAuthenticationTypes_feed-example=undefined ##[debug]which 'dotnet' ##[debug]found: '/__t/dotnet/dotnet' ##[debug]restoreArguments=undefined ##[debug]which '/__t/dotnet/dotnet' ##[debug]found: '/__t/dotnet/dotnet' ##[debug]/__t/dotnet/dotnet arg: restore ##[debug]/__t/dotnet/dotnet arg: /__w/6/s/src/Example.sln ##[debug]/__t/dotnet/dotnet arg: --configfile ##[debug]/__t/dotnet/dotnet arg: /__w/6/Nuget/tempNuGet_1004187.config ##[debug]/__t/dotnet/dotnet arg: --verbosity ##[debug]/__t/dotnet/dotnet arg: Detailed

Repro steps

1. Commit a nuget.config file with a package source and package source mapping configured for a private/internal NuGet feed (i.e., Azure Artifacts feed) to a repository in Azure DevOps.  Use the name of the feed for the package source and package source mapping key.
2. In a YAML pipeline, add a NuGetAuthenticate@1 step followed by a DotNetCoreCLI@2 step for the "restore" command with the `nugetConfigPath` input set to the path of the nuget.config in the repo (e.g., "src\nuget.config").  Set the `verbosityRestore` input to "Detailed".
3. Run the pipeline.

Expected results:
Packages in the private/internal feed are successfully restored.

Actual results:
Packages (which aren't already cached by the Agent) in the private/internal feed are not restored.  The `dotnet restore` output includes `Package source mapping match not found for package ID '...' log entries.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions