Azure Functions,无法加载文件或程序集

Azure Functions, Could not load file or assembly

在 Azure Functions 中使用 NuGet.Protocol NuGet 包时,出现以下错误:System.Private.CoreLib: Could not load file or assembly.

[4/18/2020 8:51:43 AM] The 'Function1' function is in error: Unable to load one or more of the requested types.
[4/18/2020 8:51:43 AM] Could not load file or assembly 'NuGet.Protocol, Version=5.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
[4/18/2020 8:51:43 AM] Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1'. System.Private.CoreLib: Could not load file or assembly 'NuGet.Protocol, Version=5.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

我确认 NuGet.Protocol.dll 文件存在于 bin 输出中。

为什么 Azure Functions 找不到 NuGet.Protocol.dll

这是 known-problem with Azure Functions, introduced in Microsoft.NET.Sdk.Functions v3.0.4,今天仍然存在 (v3.0.11)。

要防止 Azure Functions 删除此库,请将以下内容添加到您的 CSPROJ:

<PropertyGroup>
    <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
</PropertyGroup>

这是我如何在我的 GitTrends 应用程序中使用它的示例: https://github.com/brminnick/GitTrends/blob/22d748fc72452dcd39bb3866e30f339827ded3dd/GitTrends.Functions/GitTrends.Functions.csproj#L10