Azure 函数 V3 无法加载文件或程序集 Microsoft.Extensions.DependencyInjection.Abstractions,Version=5.0.0.0 with EF core 5.0-rc1 [英] Azure function V3 could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0 with EF core 5.0-rc1

查看:16
本文介绍了Azure 函数 V3 无法加载文件或程序集 Microsoft.Extensions.DependencyInjection.Abstractions,Version=5.0.0.0 with EF core 5.0-rc1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

案例

我们正在使用 .netcore 3.1 创建 azure function v3.使用EF core 5.0-rc1依赖注入

1) 依赖注入

[程序集:FunctionsStartup(typeof(xxxxx.Startup))]命名空间xxxxx{公共类启动:FunctionsStartup{公共覆盖无效配置(IFunctionsHostBuilder builder){var 服务 = builder.Services;var configBuilder = new ConfigurationBuilder().SetBasePath(Environment.CurrentDirectory).AddJsonFile("local.settings.json", true, reloadOnChange: true).AddEnvironmentVariables() ;配置服务(服务);ConfigureAppSettings(services, configBuilder.Build());ConfigureLogging(services, configBuilder.Build());}}}

2) EF 核心 5.0 rc-1

虽然 Entity Framework Core 5.0 RC1 不能在 .Net 标准 2.0 平台上运行,但它需要 .net 标准 2.1.所以它找不到Microsoft.Azure.Functions.Extensions.

更多细节,你可以参考这个文章.

Case

We are creating azure function v3 with .netcore 3.1. Using EF core 5.0-rc1 and Depdency Injection

1) DependecyInjection

[assembly: FunctionsStartup(typeof(xxxxx.Startup))]
namespace xxxxx
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            var services = builder.Services;
            var configBuilder = new ConfigurationBuilder()
                .SetBasePath(Environment.CurrentDirectory)
                .AddJsonFile("local.settings.json", true, reloadOnChange: true)
                .AddEnvironmentVariables() ;
            ConfigureServices(services);
            ConfigureAppSettings(services, configBuilder.Build());
            ConfigureLogging(services, configBuilder.Build());
        }
    }
}

2) EF core 5.0 rc-1

https://devblogs.microsoft.com/dotnet/announcing-entity-framework-core-efcore-5-0-rc1/

Error

Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.

Packages

Following are the packages referenced

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.1.0" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.0-rc.1.20451.14" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.7" />
    <PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
    <PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

Troubleshooting

commenting the following line in startup.cs (Dependency injection) solves the problem

[assembly: FunctionsStartup(typeof(xxxxx.Startup))]

解决方案

The Microsoft.Azure.Functions.Extensions depends on .net standard 2.0.

While the Entity Framework Core 5.0 RC1 will not run on .Net standard 2.0 platforms, it requires .net standard 2.1. So it could not find the Microsoft.Azure.Functions.Extensions.

For more details, you could refer to this article.

这篇关于Azure 函数 V3 无法加载文件或程序集 Microsoft.Extensions.DependencyInjection.Abstractions,Version=5.0.0.0 with EF core 5.0-rc1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆