无法使用 NuGet 上游源从 Azure DevOps Artifacts 源下载某些包

Some packages can't be downloaded from Azure DevOps Artifacts feed with NuGet upstream source

我创建了一个 Azure Artifact Feed 并将 nuget 库配置为上游,但是当我尝试安装包 Newtonsoft.Json.Bson 时,它总是失败并显示错误:Install-Package : NU1101: Unable to find package Newtonsoft.Json.Bson. No packages exist with this id in source(s): MyFeed, Microsoft Visual Studio Offline Packages,有些包工作正常,这让人非常困惑但有些不是。

为了让您的源提供确定性还原,请务必确保您的包源配置文件(.npmrc_ 或 _nuget.config)仅引用启用了上游源的 Azure Artifacts 源。对于 NuGet,<packageSources> 部分应如下所示:

<packageSources>
  <clear />
  <add key="FabrikamFiber" value="https://pkgs.dev.azure.com/fabrikam/_packaging/FabrikamFiber/nuget/v3/index.json" />
</packageSources>

The <clear /> tag is required because NuGet composes several configuration files to determine the full set of options to use. <clear /> tells NuGet to ignore all other <packageSources> defined in higher-level configuration files.

您必须允许从 public 存储库中提取从私有存储库中提取的包。

查看文档here

这是文档中的一个 powershell 片段,它允许从 public 存储库中获取一个包:

$env:PATVAR = "YOUR_PAT_GOES_HERE"
$token = [Convert]::ToBase64String(([Text.Encoding]::ASCII.GetBytes("username:$PatVar")))
$headers = @{
    Authorization = "Basic $token"
}
$url = 
    "https://pkgs.dev.azure.com/{OrganizationName}/{ProjectName}/_apis/packaging/feeds/{FeedName}/{Protocol}/packages/{PackageName}/upstreaming?api-version=6.1-preview.1"
$body = '{"versionsFromExternalUpstreams": "AllowExternalVersions"}'
    
Invoke-RestMethod -Uri $url -Headers $headers -Body $body -Method Patch -ContentType "application/json"