为什么 .NET 6 上的 Azure Function 正在寻找 System.ComponentModel 版本 6.0.0.0?
Why is an Azure Function on .NET 6 looking for System.ComponentModel Version 6.0.0.0?
我正在将名为“Bridge”的 Azure Function 部署到 Azure,目标是 .NET 6。该项目引用了我编写的名为“DBLibrary”的 class 库,该库的目标是 .NET Standard 2.1. Azure 函数可以 运行 在我的 PC 本地,没有 运行 时间错误。
当我将 Azure Functions 发布到 Azure 时,我在 Azure 门户中看到“Functions 运行time error”,其中显示:
Could not load file or assembly 'System.ComponentModel,
Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
The system cannot find the file specified.
我没有直接以 System.ComponentModel 为目标,而且我没有在任何 nuget 提要中看到“System.ComponentModel”的 nuget 包版本 6.0.0。为什么 Azure 函数要查找 System.ComponentModel 的这个版本 6.0.0?如果该版本确实存在,为什么 Azure Functions 找不到它?
以下是“桥梁”Azure 函数的 csproj 的相关部分:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DBLibrary\DBLibrary.csproj" />
</ItemGroup>
</Project>
以下是 Azure Function 项目引用的“DBLibrary”class 库的 csproj 的相关部分:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<ApplicationIcon />
<OutputType>Library</OutputType>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.10.0" />
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
<PackageReference Include="System.Text.Json" Version="6.0.2" />
</ItemGroup>
</Project>
我已尝试在 Azure Functions csproj 中将 _FunctionsSkipCleanOutput 设置为 true,因为这是作为解决 nuget 包解析问题的潜在解决方案提供的:
https://github.com/Azure/azure-functions-host/issues/7061
该解决方案没有改变我在 Azure 门户中看到的 运行时间错误。
您正在使用的 .net 标准 2.1
但是,Microsoft.Azure.Functions.Extensions
最多可以支持 .NET Standard 2.0
您应该将以下包添加到您的函数应用程序并再次部署到 Azure。
dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 5.0.0-rc.2.20475.6
有关详细信息,请参阅@Jeremy 的GitHub issue and this MICROSOFT BLOG。
在我的部署管道中,当我本应针对版本 ~4 以支持 .NET 6 时,我将函数运行时版本 ~2 用于 Azure 部署。更改为 Azure Functions 运行时的目标版本 4 解决了这个问题.
要在部署的 Function App 上找到此设置,请导航到 Azure 门户 (portal.azure.com) 并在那里搜索 Function App 资源的名称。在函数应用的左侧导航栏下,导航到设置 > 配置。选择“配置”部分后,在右窗格顶部查找“函数运行时设置”以验证运行时版本为“~4”。
可以在此处找到函数运行时版本差异:https://docs.microsoft.com/en-us/azure/azure-functions/functions-versions?tabs=in-process%2Cv4&pivots=programming-language-csharp
这是上述 link 支持 table 的相关部分(截至 2022 年 2 月):
Version
Support Level
Description
4.x
GA
Recommended runtime version for functions in all languages. Use this version to run C# functions on .NET 6.0.
如果您已升级到 .NET 6.0,则需要执行以下操作来解决此错误。
更新cs项目到v4
将您在 Azure 中的函数应用程序中的配置更新为以下
更新解决方案的所有 nuget 包
清理解决方案然后重新构建,它应该可以在本地工作,也应该可以在 Azure 中工作
我正在将名为“Bridge”的 Azure Function 部署到 Azure,目标是 .NET 6。该项目引用了我编写的名为“DBLibrary”的 class 库,该库的目标是 .NET Standard 2.1. Azure 函数可以 运行 在我的 PC 本地,没有 运行 时间错误。
当我将 Azure Functions 发布到 Azure 时,我在 Azure 门户中看到“Functions 运行time error”,其中显示:
Could not load file or assembly 'System.ComponentModel, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
我没有直接以 System.ComponentModel 为目标,而且我没有在任何 nuget 提要中看到“System.ComponentModel”的 nuget 包版本 6.0.0。为什么 Azure 函数要查找 System.ComponentModel 的这个版本 6.0.0?如果该版本确实存在,为什么 Azure Functions 找不到它?
以下是“桥梁”Azure 函数的 csproj 的相关部分:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DBLibrary\DBLibrary.csproj" />
</ItemGroup>
</Project>
以下是 Azure Function 项目引用的“DBLibrary”class 库的 csproj 的相关部分:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<ApplicationIcon />
<OutputType>Library</OutputType>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.10.0" />
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
<PackageReference Include="System.Text.Json" Version="6.0.2" />
</ItemGroup>
</Project>
我已尝试在 Azure Functions csproj 中将 _FunctionsSkipCleanOutput 设置为 true,因为这是作为解决 nuget 包解析问题的潜在解决方案提供的: https://github.com/Azure/azure-functions-host/issues/7061 该解决方案没有改变我在 Azure 门户中看到的 运行时间错误。
您正在使用的 .net 标准 2.1
但是,Microsoft.Azure.Functions.Extensions
最多可以支持 .NET Standard 2.0
您应该将以下包添加到您的函数应用程序并再次部署到 Azure。
dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 5.0.0-rc.2.20475.6
有关详细信息,请参阅@Jeremy 的GitHub issue and this MICROSOFT BLOG。
在我的部署管道中,当我本应针对版本 ~4 以支持 .NET 6 时,我将函数运行时版本 ~2 用于 Azure 部署。更改为 Azure Functions 运行时的目标版本 4 解决了这个问题.
要在部署的 Function App 上找到此设置,请导航到 Azure 门户 (portal.azure.com) 并在那里搜索 Function App 资源的名称。在函数应用的左侧导航栏下,导航到设置 > 配置。选择“配置”部分后,在右窗格顶部查找“函数运行时设置”以验证运行时版本为“~4”。
可以在此处找到函数运行时版本差异:https://docs.microsoft.com/en-us/azure/azure-functions/functions-versions?tabs=in-process%2Cv4&pivots=programming-language-csharp
这是上述 link 支持 table 的相关部分(截至 2022 年 2 月):
Version | Support Level | Description |
---|---|---|
4.x | GA | Recommended runtime version for functions in all languages. Use this version to run C# functions on .NET 6.0. |
如果您已升级到 .NET 6.0,则需要执行以下操作来解决此错误。
更新cs项目到v4
将您在 Azure 中的函数应用程序中的配置更新为以下
更新解决方案的所有 nuget 包
清理解决方案然后重新构建,它应该可以在本地工作,也应该可以在 Azure 中工作