dotnet restore with custom source and official fee

2020-06-27 04:18发布

问题:

I have custom Nuget repository (\\build\NugetFeed) and also i'm using nuget.org to restore my packages.

For restoring packages I use this command

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

But on my build server I get the following error

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]

and no packages from official Nuget is restored. Is there any another config options for using dotnet restore?

回答1:

Seems like a dotnet cli restore command error,

It fails if you specify the local origin first, but works otherwise

# 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

Anyway, you can always use a custom 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>

or even add it to the project itself

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

this issue seems related



标签: .net-core