从 .NET 6 升级到 .NET 8,出现错误“无法加载文件或程序集 'Microsoft.Extensions.Options,版本 = 8.0.0.0”

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

我正在努力将 Azure 函数应用程序版本从 .net6 升级到 .net8,但无论我尝试什么,最终都会出现以下错误

找到C:\XXXXXXXX\Project.csproj。用于用户机密文件配置。 在外部启动类中配置服务时出错。 在外部启动类中配置服务时出错。项目:无法加载文件或程序集“Microsoft.Extensions.Options,Version=8.0.0.0,Culture=neutral,PublicKeyToken=adb9793829ddae60”。系统找不到指定的文件。 启动操作“f5a77300-36f2-4210-803e-0ef503e6f29d”期间发生主机错误。 Microsoft.Azure.WebJobs.Script:在外部启动类中配置服务时出错。项目:无法加载文件或程序集“Microsoft.Extensions.Options,Version=8.0.0.0,Culture=neutral,PublicKeyToken=adb9793829ddae60”。系统找不到指定的文件。 值不能为空。 (参数“提供者”)

我尝试过的:

  1. 安装了最新/较低版本的“Microsoft.Extensions.Options”
  2. 通过 Nuget Manager 更新了所有包
  3. 使用 Visual Studio 更新了解决方案中的所有项目 -> 升级助手工具
  4. 以不同的方法甚至尝试手动将项目升级到 .NET 8
  5. 更新了 local.settings 文件 "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"

项目csproj

    <Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <NoWarn>1591</NoWarn>
    <Nullable>enable</Nullable>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Azure.Identity" Version="1.13.1" />
    <PackageReference Include="Azure.Storage.Blobs" Version="12.22.2" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.23.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.2.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.3.2" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.13.7" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi.Core" Version="1.5.1" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="4.0.1" />
    <PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
    <PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.6.0" />
    <PackageReference Include="System.Formats.Asn1" Version="8.0.1" />
    <PackageReference Include="System.Net.Http" Version="4.3.4" />
    <PackageReference Include="System.Security.Cryptography.Pkcs" Version="8.0.1" />
    <PackageReference Include="System.ServiceModel.Duplex" Version="6.0.0" />
    <PackageReference Include="System.ServiceModel.Http" Version="8.0.0" />
    <PackageReference Include="System.ServiceModel.NetTcp" Version="8.0.0" />
    <PackageReference Include="System.ServiceModel.Security" Version="6.0.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.1.7" />
    <PackageReference Include="System.Text.Json" Version="8.0.5" />
    <PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\Project.Contract\Project.Contract.csproj" />
    <ProjectReference Include="..\Project.Data\Project.Data.csproj" />
  </ItemGroup>
  <ItemGroup>
    <None Update="Data\RecourceType.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
  </ItemGroup>
</Project>
c# .net azure-functions .net-6.0 .net-8.0
1个回答
0
投票

我可以看到您在 .csproj 中仍然有

进程内相关包

<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.13.7" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi.Core" Version="1.5.1" />

如果要将功能从进程内迁移到隔离模型,则必须相应地安装软件包。

卸载或删除上述软件包并安装以下工作软件包,请参阅MSDOC

Microsoft.AspNetCore.App
Microsoft.Azure.Functions.Worker.Extensions.DurableTask
Microsoft.Azure.Functions.Worker.Extensions.OpenApi

我创建了一个简单的.NET 8.0隔离的Azure Durable函数。

.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.23.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.4.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.1.7" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.2.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.3.2" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.OpenApi" Version="1.5.1" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.18.1" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="4.0.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>
    <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
  </ItemGroup>
</Project>

local.settings.json:

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
    }
}

回复:

enter image description here

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