我有一个自定义库,它已打包并作为 nuget 包发布到此服务器:
https://pkgs.dev.azure.com/my-project-feed/_packaging/my-project-feed/nuget/v3/index.json
据我所知,这是一个公共网址(访问受限[在本例中是假的])。
我可以将我的库作为 nuget 包添加到我的客户端应用程序中,一切都会按预期构建和运行,因此至少在本地一切都很好。
但是,在 azure Devops 管道上,构建失败并出现以下异常:
##[error]The nuget command failed with exit code(1) and error(NU1101: Unable to find package My.Custom.Package. No packages exist with this id in source(s): {C path}\dotnet\library-packs, NuGetOrg
Errors in {D path}\My.Blazor.Client\My.Blazor.Client.csproj
NU1101: Unable to find package My.Custom.Package. No packages exist with this id in source(s): {C path}\dotnet\library-packs, NuGetOrg)
##[error]Packages failed to restore
如果我通过 dll 将包添加为项目引用,则构建工作正常。
我的第一个怀疑是这是一个权限问题。我们正在设置此环境以供首次使用,因此我们可能错过了一些东西。
我尝试过的
定义了两个项目构建服务组,我尝试给予他们两个
Contributor
权限,其中一个只有协作者,但这并没有改变任何东西。
我的问题
将
NuGet.config
文件添加到您的解决方案中并添加以下行:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value=".\packages" />
</config>
<packageSources>
<add key="nuget.org" value ="https://api.nuget.org/v3/index.json"/>
<add key="ProGet" value="https://pkgs.dev.azure.com/my-project-feed/_packaging/my-project-feed/nuget/v3/index.json" />
</packageSources>
</configuration>
然后在恢复包时在您的管道中:
- task: DotNetCoreCLI@2
displayName: Restore packages
inputs:
command: restore
feedsToUse: config
projects: '$(path-to-solution)'
nugetConfigPath: 'NuGet.config'
verbosityRestore: Normal
includeNuGetOrg: true