Rup*_*esh 11 dependency-injection entity-framework-core azure-functions
我们正在使用 .netcore 3.1 创建 azure 函数 v3。使用EF 核心 5.0-rc1和依赖注入
[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());
}
}
}
Run Code Online (Sandbox Code Playgroud)
https://devblogs.microsoft.com/dotnet/annoucing-entity-framework-core-efcore-5-0-rc1/
无法加载文件或程序集“Microsoft.Extensions.DependencyInjection.Abstractions,Version=5.0.0.0,Culture=neutral,PublicKeyToken=adb9793829ddae60”。该系统找不到指定的文件。

以下是引用的包

<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>
Run Code Online (Sandbox Code Playgroud)
在startup.cs(依赖注入)中注释以下行即可解决问题
[assembly: FunctionsStartup(typeof(xxxxx.Startup))]
Run Code Online (Sandbox Code Playgroud)
Niv*_*nan 10
如果您使用 .NET Core 3.1 或更低版本。将Microsoft.Extensions.DependencyInjection和Microsoft.Extensions.DependencyInjection.Abstractions的 NuGet 包降级到 3.xx
这Microsoft.Azure.Functions.Extensions 取决于 .net 标准 2.0。
虽然Entity Framework Core 5.0 RC1 不会在 .Net 标准 2.0 平台上运行,但它需要.net 标准 2.1。所以它找不到Microsoft.Azure.Functions.Extensions.
更多细节,你可以参考这篇文章。
| 归档时间: |
|
| 查看次数: |
7442 次 |
| 最近记录: |