Azure Functions启动时无法加载Microsoft.Extensions.Configuration.Abstractions程序集
问题分析
你遇到的是依赖版本冲突问题:.NET 8 对应的 Microsoft.Extensions.Configuration.Abstractions 版本应为 8.x,但项目中存在依赖间接引用了 9.0.0.0 版本,导致运行时找不到对应程序集——即使手动安装该包,也可能因依赖优先级或绑定重定向问题未生效。
解决方案
按以下步骤排查修复:
1. 锁定依赖版本
直接在 Function App 的 .csproj 中添加对 Microsoft.Extensions.Configuration.Abstractions 的显式引用,锁定到 .NET 8 兼容的版本(如 8.0.0):
<ItemGroup> <!-- 保留原有包引用,新增以下行 --> <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" /> </ItemGroup>
2. 定位间接依赖来源
执行命令查看完整依赖链,找出哪个包/项目引入了 9.0 版本的组件:
dotnet list package --include-transitive
重点排查你引用的 HROne.Events.Services、HROne.Redis 等子项目,大概率是这些类库引用了更高版本的 Microsoft.Extensions.* 包,导致版本溢出到主项目。
3. 统一子项目依赖
确保所有引用的子项目(HROne 系列)的目标框架均为 net8.0,且它们的 Microsoft.Extensions.* 依赖版本统一为 8.x,避免跨版本引用。
4. 更新 Functions SDK
你的 Microsoft.NET.Sdk.Functions 版本为 4.4.1,属于较旧版本,建议升级到兼容 .NET 8 的最新稳定版(如 4.28.1),新版本对依赖冲突的处理更完善:
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.28.1" />
5. 清理缓存并重建
- 删除项目的
bin和obj文件夹 - 清理 NuGet 缓存:
dotnet nuget locals all --clear
- 重新恢复依赖并构建:
dotnet restore dotnet build
附:你的代码参考
Startup 类
#region Dependency using Microsoft.Azure.Functions.Extensions.DependencyInjection; #endregion [assembly: FunctionsStartup(typeof(HROne.Events.FunctionApp.Startup))] namespace HROne.Events.FunctionApp; public class Startup : FunctionsStartup { public override void Configure(IFunctionsHostBuilder builder) { FunctionsHostBuilderContext context = builder.GetContext(); builder.Services.RegisterApplicationServices(context.ApplicationRootPath); } }
.csproj 文件
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <AzureFunctionsVersion>v4</AzureFunctionsVersion> </PropertyGroup> <ItemGroup> <None Remove="AzureAppConfigurationMapper.json" /> <None Remove="EmailTemplate\CommonNotificationMail.html" /> <None Remove="EmailTemplate\DeadLetterInfo.html" /> <None Remove="EmailTemplate\TimesheetReminderMail.html" /> </ItemGroup> <ItemGroup> <Content Include="EmailTemplate\CommonNotificationMail.html"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> <Content Include="EmailTemplate\DeadLetterInfo.html"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> <ItemGroup> <Content Include="AzureAppConfigurationMapper.json"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> <Content Include="EmailTemplate\TimesheetReminderMail.html"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> <ItemGroup> <PackageReference Include="Azure.Messaging.EventHubs" Version="5.11.5" /> <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" /> <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.13.5" /> <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.16.4" /> <PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="7.3.0" /> <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.4.1" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\..\HROne.BusinessLayer\HROne.Events.Services\HROne.Events.Services.csproj" /> <ProjectReference Include="..\..\HROne.BusinessLayer\HROne.Redis\HROne.Redis.csproj" /> <ProjectReference Include="..\..\HROne.BusinessLayer\HROne.Shared.Services\HROne.Shared.Services.csproj" /> <ProjectReference Include="..\..\HROne.DataModels\HROne.Events.Models\HROne.Events.Models.csproj" /> <ProjectReference Include="..\..\HROne.Repositories\HROne.Events.Repositories\HROne.Events.Repositories.csproj" /> <ProjectReference Include="..\..\HROne.Shared\HROne.Common\HROne.Common.csproj" /> </ItemGroup> <ItemGroup> <Using Include="HROne.Constants" /> </ItemGroup> <ItemGroup> <None Update="AppSettings.json"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> <None Update="AppSettings.Test.json"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> <None Update="EmailTemplate\ImportException.html"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> <None Update="EmailTemplate\ImportPartial.html"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> <None Update="EmailTemplate\MailTemplateImages\hrone_btn.png"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Update="EmailTemplate\MailTemplateImages\Welcome_header.jpg"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Update="EmailTemplate\NotificationMail.html"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> <None Update="EmailTemplate\SingleSignOnWelcome.html"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Update="EmailTemplate\Welcome.html"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Update="EmailTemplate\WelcomeValidationMail.html"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Update="host.json"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> <None Update="local.settings.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToPublishDirectory>Never</CopyToPublishDirectory> </None> </ItemGroup> <Target Name="PostBuild" AfterTargets="PostBuildEvent"> <Exec Command="xcopy "$(TargetDir)newrelic\*.*" "$(TargetDir)..\newrelic" /Y /I /S" /> </Target> </Project>
内容的提问来源于stack exchange,提问作者pratapsingh845
相关产品推荐
相关产品推荐

