You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

构建代理上Dotnet Restore失败:PackageSourceMapping未识别私有NuGet源

Azure Pipelines中NuGet包源映射导致私有源包还原失败

我用私有NuGet源托管应用依赖包,通过Azure Pipelines构建时遇到了PackageSourceMapping相关的还原问题。已按官方指南完成配置:安装工具并执行packagesourcemapper generate nuget.config --remove-unused-sources生成源映射,本地通过清理NuGet缓存、重启VS、干净还原验证,运行完全正常。

但在构建代理上执行以下任务时,还原失败:

- task: NuGetToolInstaller@1
  displayName: Use latest NuGet
  inputs:
    checkLatest: true

- task: UseDotNet@2
  displayName: 'Use global.json SDK'
  inputs:
    packageType: 'sdk'
    useGlobalJson: true

- task: DotNetCoreCLI@2
  displayName: dotnet restore
  inputs:
    command: 'restore'
    projects: ${{ parameters.solution }}
    feedsToUse: 'config'
    nugetConfigPath: 'NuGet.config'

报错信息:

/Users/runner/work/1/s/tests/MyApp.UnitTests/MyApp.UnitTests.csproj : error NU1100: Unable to resolve 'Acme.MyPackage (>= X.X.X-pre)' for 'net8.0'. PackageSourceMapping is enabled, the following source(s) were not considered: /Users/runner/hostedtoolcache/dotnet/library-packs, feed-MyApp, nuget.org. [/Users/runner/work/1/s/MyApp.sln]

我的NuGet.config配置如下:

包源配置

<packageSources>
    <clear />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="Acme" value="https://pkgs.dev.azure.com/Acme/MyApp/_packaging/MyFeed/nuget/v3/index.json" />
</packageSources>

包源映射配置

<packageSourceMapping>
  <clear />
  <packageSource key="nuget.org">
    <package pattern="*" />
  </packageSource>
  <packageSource key="Acme">
    <package pattern="Acme.*" />
  </packageSource>
</packageSourceMapping>
<disabledPackageSources>
    <clear />
</disabledPackageSources>

查阅官方文档后仍未找到问题根源。我不理解为何NuGet在已有源映射的情况下完全忽略私有源——即便尝试用PackageSourceMapper生成所有包的显式名称配置,问题依旧。更困惑的是,报错信息里明明列出了私有源,却在解析私有包时不使用它?

内容的提问来源于stack exchange,提问作者Axemasta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 15:10:16