无法加载文件或程序集“Microsoft.Extensions.DependencyModel,版本=6.0.0.0

问题描述 投票:0回答:1

我有一个 Azure 函数(HTTP 触发器)并尝试使用 EF。但是,我一直遇到这个错误:

System.Private.CoreLib: Exception while executing function: OrdersExportFunction. RazorLight: Could not load file or assembly 'Microsoft.Extensions.DependencyModel, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.

这是我的项目配置:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <PreserveCompilationReferences>true</PreserveCompilationReferences>
    <PreserveCompilationContext>true</PreserveCompilationContext>
  </PropertyGroup>
    <PropertyGroup>
        <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
        <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
    </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="HtmlRenderer.PdfSharp" Version="1.5.0.6" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.9" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.9" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
    <PackageReference Include="RazorLight" Version="2.3.1" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
    <ItemGroup>
        <None Remove="Views\Shared\OrderSummaryByCustomerTemplate.cshtml" />
    </ItemGroup>
    <ItemGroup>
        <EmbeddedResource Include="Views\Shared\OrderSummaryByCustomerTemplate.cshtml">
            <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        </EmbeddedResource>
    </ItemGroup>
</Project>

按铃吗?

c# entity-framework azure-functions
1个回答
0
投票

很可能是由于清理函数主机上已存在但版本不同的依赖项引起的。

您可能想添加到您的 csproj

<ItemGroup>
    <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
</ItemGroup>

为了避免删除任何可能导致函数主机出现不同问题的依赖项,或者您可以添加

<ItemGroup>
    <FunctionsPreservedDependencies Include="Microsoft.Extensions.DependencyModel" />
</ItemGroup> 

仅保留选定的依赖项。

相关信息:

GitHub - FunctionsPreservedDependency 的关注#2349

GitHub - _FunctionsSkipCleanOutput/FunctionsSkipCleanOutput/FunctionsPreservedDependency 是 Functions 团队创建的问题的解决方案 #7601

© www.soinside.com 2019 - 2024. All rights reserved.