我有一个 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>
按铃吗?
很可能是由于清理函数主机上已存在但版本不同的依赖项引起的。
您可能想添加到您的 csproj
<ItemGroup>
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
</ItemGroup>
为了避免删除任何可能导致函数主机出现不同问题的依赖项,或者您可以添加
<ItemGroup>
<FunctionsPreservedDependencies Include="Microsoft.Extensions.DependencyModel" />
</ItemGroup>
仅保留选定的依赖项。
相关信息: