You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将Azure Function框架从3.1升级至5后遇程序集加载错误,求解决方案

解决方案

1. 切换到独立工作进程模型

.NET 5 Azure Function不支持传统的In-Process运行模型,必须使用Isolated Worker Model。打开项目的.csproj文件,确认以下配置:

<PropertyGroup>
  <TargetFramework>net5.0</TargetFramework>
  <AzureFunctionsVersion>v4</AzureFunctionsVersion>
  <OutputType>Exe</OutputType>
</PropertyGroup>

OutputType设为Exe是独立进程模型的核心标志,必须配置。

2. 替换并统一NuGet包

  • 删除原项目中的Microsoft.NET.Sdk.Functions包(该包仅适用于In-Process模型)
  • 安装Microsoft.Azure.Functions.Worker和Microsoft.Azure.Functions.Worker.Sdk包,选择与.NET 5兼容的版本(推荐1.8.x系列)
  • 确保所有Microsoft.Extensions.*相关包的版本统一为5.0.x,避免版本冲突。示例包引用配置:
<ItemGroup>
  <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.8.0" />
  <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.7.0" />
  <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
</ItemGroup>

3. 清理重建项目

执行以下命令清理缓存并重新构建:

dotnet clean
dotnet restore
dotnet build

4. 升级本地开发工具

确保本地安装的Azure Functions Core Tools版本为v4及以上,这是支持.NET 5独立进程模型的最低要求。通过以下命令检查版本:

func --version

若版本低于4.x,需下载升级。

5. 配置Azure云端环境

部署到Azure时,需在Function App的配置页面完成两项设置:

  • 将FUNCTIONS_WORKER_RUNTIME的值设为dotnet-isolated
  • 确认应用服务计划的运行栈设置为.NET 5(弹性高级计划或专用计划支持该配置)

内容的提问来源于stack exchange,提问作者John John

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 17:01:19