Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 13, 2026

Fixes #52439.

The FileBasedApp_CentralPackageManagement_NoVersionSpecified_KeepExisting test was failing when noRestore=false due to NuGet requiring package source mapping when using Central Package Management with multiple sources. Without it, NuGet issued NU1507 warnings and NU1101 errors for packages not available on all configured sources.

Changes

  • Added local NuGet.config creation in test setup with package source mapping
    • Maps Humanizer* packages to nuget.org
    • Maps all other packages to darc-pub-dotnet-dotnet feed
    • Clears inherited sources to avoid configuration conflicts

This satisfies NuGet's Central Package Management requirements and ensures all packages restore from appropriate sources.

// Test now creates a local NuGet.config with proper source mapping
var nugetConfig = Path.Join(testInstance.Path, "NuGet.config");
File.WriteAllText(nugetConfig, """
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <packageSources>
        <clear />
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
        <add key="darc-pub-dotnet-dotnet" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-dotnet-4ef9fba1/nuget/v3/index.json" />
      </packageSources>
      <packageSourceMapping>
        <packageSource key="nuget.org">
          <package pattern="Humanizer*" />
        </packageSource>
        <packageSource key="darc-pub-dotnet-dotnet">
          <package pattern="*" />
        </packageSource>
      </packageSourceMapping>
    </configuration>
    """);

All test combinations now pass, including previously failing scenarios with noRestore=false.

Original prompt

This section details on the original issue you should resolve

<issue_title>GivenDotnetPackageAdd noRestore=false fails to work with package source mapping</issue_title>
<issue_description>A Package Add test is failing when no restore is set to false.
This appears to impact release/10.0.1xx and release/10.0.2xx at the very least.

Microsoft.DotNet.Cli.Package.Add.Tests.GivenDotnetPackageAdd.Microsoft.DotNet.Cli.Package.Add.Tests.GivenDotnetPackageAdd.FileBasedApp_CentralPackageManagement_NoVersionSpecified_KeepExisting(legacyForm: True, fileOption: False, noRestore: False)

Expected value to be 0 because Expected command to pass but it did not.
Working Directory: /datadisks/disk1/work/AE91097D/t/dotnetSdkTests.JSkrMId3/FileBasedApp_---36A7B5DD_5
File Name: /datadisks/disk1/work/AE91097D/p/d/dotnet
Arguments: add Program.cs package Humanizer
Exit Code: 1
StdOut:
Determining projects to restore...
/datadisks/disk1/work/AE91097D/t/dotnetSdkTests.JSkrMId3/FileBasedApp_---36A7B5DD_5/Program.csproj : warning NU1507: There are 13 package sources defined in your configuration. When using central package management, please map your package sources with package source mapping (https://aka.ms/nuget-package-source-mapping) or specify a single package source. The following sources are defined: darc-pub-dotnet-dotnet-fad253f, dotnet6, dotnet7, dotnet8, dotnet8-transport, dotnet8-workloads, dotnet9, dotnet9-transport, dotnet10, dotnet10-transport, dotnet-public, dotnet-tools, test-tools
/datadisks/disk1/work/AE91097D/t/dotnetSdkTests.JSkrMId3/FileBasedApp_---36A7B5DD_5/Program.csproj : error NU1101: Unable to find package Humanizer.Core.bn. No packages exist with this id in source(s): darc-pub-dotnet-dotnet-fad253f, dotnet-public, dotnet-tools, dotnet10, dotnet10-transport, dotnet6, dotnet7, dotnet8, dotnet8-transport, dotnet8-workloads, dotnet9, dotnet9-transport, Package source 1, Package source 2, test-tools
/datadisks/disk1/work/AE91097D/t/dotnetSdkTests.JSkrMId3/FileBasedApp_---36A7B5DD_5/Program.csproj : error NU1101: Unable to find package Humanizer.Core.ca. No packages exist with this id in source(s): darc-pub-dotnet-dotnet-fad253f, dotnet-public, dotnet-tools, dotnet10, dotnet10-transport, dotnet6, dotnet7, dotnet8, dotnet8-transport, dotnet8-workloads, dotnet9, dotnet9-transport, Package source 1, Package source 2, test-tools
/datadisks/disk1/work/AE91097D/t/dotnetSdkTests.JSkrMId3/FileBasedApp_---36A7B5DD_5/Program.csproj : error NU1101: Unable to find package Humanizer.Core.fi. No packages exist with this id in source(s): darc-pub-dotnet-dotnet-fad253f, dotnet-public, dotnet-tools, dotnet10, dotnet10-transport, dotnet6, dotnet7, dotnet8, dotnet8-transport, dotnet8-workloads, dotnet9, dotnet9-transport, Package source 1, Package source 2, test-tools
/datadisks/disk1/work/AE91097D/t/dotnetSdkTests.JSkrMId3/FileBasedApp_---36A7B5DD_5/Program.csproj : error NU1101: Unable to find package Humanizer.Core.fil. No packages exist with this id in source(s): darc-pub-dotnet-dotnet-fad253f, dotnet-public, dotnet-tools, dotnet10, dotnet10-transport, dotnet6, dotnet7, dotnet8, dotnet8-transport, dotnet8-workloads, dotnet9, dotnet9-transport, Package source 1, Package source 2, test-tools
/datadisks/disk1/work/AE91097D/t/dotnetSdkTests.JSkrMId3/FileBasedApp_---36A7B5DD_5/Program.csproj : error NU1101: Unable to find package Humanizer.Core.ko. No packages exist with this id in source(s): darc-pub-dotnet-dotnet-fad253f, dotnet-public, dotnet-tools, dotnet10, dotnet10-transport, dotnet6, dotnet7, dotnet8, dotnet8-transport, dotnet8-workloads, dotnet9, dotnet9-transport, Package source 1, Package source 2, test-tools
/datadisks/disk1/work/AE91097D/t/dotnetSdkTests.JSkrMId3/FileBasedApp_---36A7B5DD_5/Program.csproj : error NU1101: Unable to find package Humanizer.Core.lb. No packages exist with this id in source(s): darc-pub-dotnet-dotnet-fad253f, dotnet-public, dotnet-tools, dotnet10, dotnet10-transport, dotnet6, dotnet7, dotnet8, dotnet8-transport, dotnet8-workloads, dotnet9, dotnet9-transport, Package source 1, Package source 2, test-tools
/datadisks/disk1/work/AE91097D/t/dotnetSdkTests.JSkrMId3/FileBasedApp_---36A7B5DD_5/Program.csproj : error NU1101: Unable to find package Humanizer.Core.lt. No packages exist with this id in source(s): darc-pub-dotnet-dotnet-fad253f, dotnet-public, dotnet-tools, dotnet10, dotnet10-transport, dotnet6, dotnet7, dotnet8, dotnet8-transport, dotnet8-workloads, dotnet9, dotnet9-transport, Package source 1, Package source 2, test-tools
/datadisks/disk1/work/AE91097D/t/dotnetSdkTests.JSkrMId3/FileBasedApp_---36A7B5DD_5/Program.csproj : error NU1101: Unable to find package Humanizer.Core.ms. No packages exist with this id in source(s): darc-pub-dotnet-dotnet-fad253f, dotnet-public, dotnet-tools, dotnet10, dotnet10-transport, dotnet6, dotnet7, dotnet8, dotnet8-transport, dotnet8-workloads, dotnet9, dotnet9-transport, Package source 1, Package source 2, test-tools
/datadisks/disk1...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes dotnet/sdk#52439

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

Copilot AI changed the title [WIP] Fix GivenDotnetPackageAdd test failure with noRestore set to false Fix GivenDotnetPackageAdd test failures with package source mapping for Central Package Management Jan 13, 2026
Copilot AI requested a review from nagilson January 13, 2026 22:44
@jjonescz
Copy link
Member

I have (I think better) fix here: #52450

@nagilson
Copy link
Member

closing in favor of better fix

@nagilson nagilson closed this Jan 14, 2026
@jjonescz jjonescz deleted the copilot/fix-package-add-test-failure branch January 15, 2026 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants