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

Azure Pipelines部署无网本地服务器时Dotnet API还原构建失败

解决Azure Pipelines离线环境构建Dotnet Api的NU1301错误

问题场景

在无网络连接的本地服务器环境中,使用Azure Pipelines还原/构建Dotnet Api时,触发以下错误:

C:\agent_work\1\s\WebApplication1\WebApplication1.csproj : error NU1301: Unable to load the service index for source https://api.nuget.org/v3/index.json.

核心原因

离线环境下,Azure Pipelines代理无法访问公共NuGet源,导致NuGet包还原失败。

解决方案

1. 搭建本地私有NuGet源

  • 提前将项目依赖的所有NuGet包下载到本地服务器的指定目录(例如D:\LocalNuGetRepo)
  • 在本地服务器执行命令创建私有源:
    nuget sources add -name "LocalNuGet" -source "D:\LocalNuGetRepo"
    

2. 修改项目NuGet配置

在项目根目录创建或更新NuGet.Config,清除默认公共源并指定本地私有源:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="LocalNuGet" value="D:\LocalNuGetRepo" />
  </packageSources>
</configuration>

3. 调整Azure Pipelines还原任务

在Dotnet Restore任务的Arguments字段中添加参数,指定使用本地配置文件:

--configfile "$(Build.SourcesDirectory)/NuGet.Config"

同时确保构建代理对本地NuGet源目录有读写权限。

4. 备选方案(内部网络可用时)

如果本地服务器能访问内部Azure DevOps服务器,可将依赖包上传至Azure Artifacts,然后在NuGet.Config中配置该Artifacts源,替代公共NuGet源。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 23:17:41