使用自定义 nuget.config 的 webapp 的 nuget 包恢复失败

nuget package restore fails for webapp with custom nuget.config

我正在尝试解决我在为具有自定义包源的 .net core 2.0 webapi 恢复 nuget 包时遇到的问题。

基本上,当包含 nuget.config 时,任何 Microsoft 软件包都无法安装,因为它似乎忽略了我的 nuget 引用。

我找到了一个解决方法,那就是删除我的自定义 nuget.config,让构建失败,一旦失败,它将从 nuget.org 下载正确的东西,然后通过添加自定义文件返回,它将从磁盘恢复那些微软包,然后获取我的自定义 nuget 包。

我的 nuget 包配置如下所示:

    <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="ASPNET Team" value="https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json" />
    <add key="OTL" value="https://www.myget.org/F/{redacted}/api/v3/index.json" />
  </packageSources>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <bindingRedirects>
    <add key="skip" value="False" />
  </bindingRedirects>
  <packageManagement>
    <add key="format" value="0" />
    <add key="disabled" value="False" />
  </packageManagement>
  <disabledPackageSources />
</configuration>

Kudu 的错误是:

An error occurred while sending the request.
    A connection with the server could not be established
  Retrying 'FindPackagesByIdAsync' for source 'https://www.myget.org/F/{redacted}/api/v3/flatcontainer/microsoft.extensions.caching.sqlserver/index.json'.
  An error occurred while sending the request.
    A connection with the server could not be established
  Retrying 'FindPackagesByIdAsync' for source 'https://dotnetmyget.blob.core.windows.net/artifacts/aspnetcore-ci-dev/nuget/v3/flatcontainer/microsoft.extensions.hosting.abstractions/index.json'.
  An error occurred while sending the request.
    A connection with the server could not be established
  Retrying 'FindPackagesByIdAsync' for source 'https://dotnetmyget.blob.core.windows.net/artifacts/aspnetcore-ci-dev/nuget/v3/flatcontainer/microsoft.extensions.caching.sqlserver/index.json'.
  An error occurred while sending the request.
    A connection with the server could not be established
  Retrying 'FindPackagesByIdAsync' for source 'https://dotnetmyget.blob.core.windows.net/artifacts/aspnetcore-ci-dev/nuget/v3/flatcontainer/microsoft.entityframeworkcore.tools/index.json'.
  An error occurred while sending the request.
    A connection with the server could not be established
  Retrying 'FindPackagesByIdAsync' for source 'https://www.myget.org/F/{redacted}/api/v3/flatcontainer/microsoft.extensions.dependencyinjection.abstractions/index.json'.
  An error occurred while sending the request.
    A connection with the server could not be established
  Retrying 'FindPackagesByIdAsync' for source 'https://dotnetmyget.blob.core.windows.net/artifacts/aspnetcore-ci-dev/nuget/v3/flatcontainer/microsoft.extensions.dependencyinjection.abstractions/index.json'.
  An error occurred while sending the request.
    A connection with the server could not be established
  Retrying 'FindPackagesByIdAsync' for source 'https://www.myget.org/F/{redacted}/api/v3/flatcontainer/microsoft.extensions.caching.sqlserver/index.json'.

直接从 Kudu 控制台执行 dotnet 还原会产生相同的结果。我已经从我的开发机器中提取了 NuGet.config,我知道它成功地恢复了微软包和自定义包并尝试使用它但它仍然失败。

我开始认为它是 azure 中的出站端口阻止防火墙的东西,但是在 webapp 上对出站防火墙或代理进行了一些谷歌搜索并没有取得成果。

因此,在与 Kudu 团队和 Nuget 团队进行研究和打交道之后,我们发现 Azure WebApps 在基本层和免费层中的线程数量有限,并且当 nuget 恢复发生时,它以并行异步方式进行,并且它命中了线程限制并失败。

要修复,您必须在 dotnet restore 上使用 --disable-parallel 部署自定义部署脚本。