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

Azure DevOps构建依赖外部包源的.NET Core应用遇NU1301错误如何解决?

解决Azure DevOps构建.NET Core应用时本地NuGet源路径错误问题

问题分析

错误提示The local source '/home/vsts/work/1/Nuget/lib' doesn't exist,但你的lib目录实际位于代码仓库根目录(/home/vsts/work/1/s/lib),核心原因是:

  • NuGet.config中的相对路径./lib在任务执行时被错误解析,指向了NuGet的默认缓存目录而非项目根目录
  • 重复的Restore任务可能导致路径解析冲突

解决方案

1. 修改NuGet.config的本地源路径为绝对路径(推荐)

使用Azure DevOps预定义变量$(Build.SourcesDirectory)(指向代码仓库根目录)替换相对路径,确保路径解析准确:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageSources>
        <clear />
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
        <add key="Public" value="https://microsofthealthoss.pkgs.visualstudio.com/FhirServer/_packaging/Public/nuget/v3/index.json" />
        <add key="local" value="$(Build.SourcesDirectory)/lib" />
    </packageSources>
</configuration>

2. 移除重复的Restore任务

当前配置包含NuGetCommand@2和DotNetCoreCLI@2两个Restore任务,冗余且可能引发冲突,保留DotNetCoreCLI@2的Restore任务即可,并明确指定NuGet.config的绝对路径:

- task: DotNetCoreCLI@2
  displayName: "Restore dotnet packages"
  inputs:
    command: restore
    projects: "**/*.csproj"
    feedsToUse: 'config'
    nugetConfigPath: '$(Build.SourcesDirectory)/NuGet.config'
- task: DotNetCoreCLI@2
  displayName: "Build with Development configuration"
  inputs:
    projects: "**/ProductX.HIS.WebApi/**/*.csproj"
    arguments: "--configuration Development"

3. 验证本地目录存在性(可选)

添加脚本任务确认lib目录存在,排除克隆或权限问题:

- script: |
    ls -la $(Build.SourcesDirectory)/lib
  displayName: "Verify local lib directory"

4. 检查子项目的包引用

确认lib/FHIR-Converter-main/src/Microsoft.Health.Fhir.Liquid.Converter/Microsoft.Health.Fhir.Liquid.Converter.csproj中没有硬编码错误的本地源路径,所有包引用应遵循NuGet.config的配置。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 09:25:13