Dot-Net-Core

使用自定義源和官方提要進行 dotnet restore

  • October 16, 2020

我有自定義 Nuget 儲存庫(\build\NugetFeed),而且我正在使用 nuget.org 來恢復我的包。

為了恢復包我使用這個命令

dotnet restore --source \\build\NugetFeed --source https://api.nuget.org/v3/index.json --verbosity n

但是在我的建構伺服器上,我收到以下錯誤

C:\Program Files\dotnet\sdk\2.2.107\NuGet.targets(114,5): error : The local source 'D:\BuildAgent\_work\5\s\https:\api.nuget.org\v3\index.json' doesn't exist. [D:\BuildAgent\_work\5\s\MyCode.sln]

並且沒有恢復來自官方 Nuget 的包。使用 dotnet restore 還有其他配置選項嗎?

似乎是 dotnet cli restore 命令錯誤。

如果您先指定本地原點,它會失敗,否則會起作用。

# Fails
dotnet restore --source /tmp/Nuget --source https://api.nuget.org/v3/index.json
#Works
dotnet restore --source https://api.nuget.org/v3/index.json --source /tmp/Nuget

無論如何,您始終可以使用自定義 Nuget.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <packageSources>
   <add key="nuget.org" value="https://www.nuget.org/api/v3/index.json" />
   <add key="local" value="/tmp/Nuget" />
 </packageSources>
</configuration>

甚至將其添加到項目本身

<PropertyGroup>
     <RestoreSources>$(RestoreSources);https://api.nuget.org/v3/index.json;/tmp/Nuget</RestoreSources>
 </PropertyGroup>

這個問題似乎相關

引用自:https://stackoverflow.com/questions/56231780