函数应用SDH从3.0.x升级到4.0.x

Function app SDH Upgrade from 3.0.x to 4.0.x

我正在尝试将函数应用程序 sdk 从 3.0.x 升级到 4.0.x

<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.13" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />

我也参考了

<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.2.1" />

但是,在函数应用程序 sdk 升级后,构建失败并出现以下异常。

Severity    Code    Description Project File    Line    Suppression State
Error       Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Microsoft.Azure.WebJobs.ServiceBus, Version=4.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
   at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name)
   at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
   at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
   at Mono.Cecil.ModuleDefinition.Resolve(TypeReference type)
   at Mono.Cecil.TypeReference.Resolve()
   at MakeFunctionJson.AttributeExtensions.IsWebJobsAttribute(CustomAttribute attribute) in /_/src/Microsoft.NET.Sdk.Functions.Generator/AttributeExtensions.cs:line 52
   at MakeFunctionJson.ParameterInfoExtensions.<>c.<IsWebJobSdkTriggerParameter>b__0_0(CustomAttribute a) in /_/src/Microsoft.NET.Sdk.Functions.Generator/ParameterInfoExtensions.cs:line 19
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at MakeFunctionJson.ParameterInfoExtensions.IsWebJobSdkTriggerParameter(ParameterDefinition parameterInfo) in /_/src/Microsoft.NET.Sdk.Functions.Generator/ParameterInfoExtensions.cs:line 17
   at MakeFunctionJson.MethodInfoExtensions.<>c.<HasTriggerAttribute>b__4_0(ParameterDefinition p) in /_/src/Microsoft.NET.Sdk.Functions.Generator/MethodInfoExtensions.cs:line 40
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at MakeFunctionJson.MethodInfoExtensions.HasTriggerAttribute(MethodDefinition method) in /_/src/Microsoft.NET.Sdk.Functions.Generator/MethodInfoExtensions.cs:line 40
   at MakeFunctionJson.MethodInfoExtensions.HasValidWebJobSdkTriggerAttribute(MethodDefinition method) in /_/src/Microsoft.NET.Sdk.Functions.Generator/MethodInfoExtensions.cs:line 24
   at MakeFunctionJson.FunctionJsonConverter.GenerateFunctions(IEnumerable`1 types)+MoveNext() in /_/src/Microsoft.NET.Sdk.Functions.Generator/FunctionJsonConverter.cs:line 134
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons() in /_/src/Microsoft.NET.Sdk.Functions.Generator/FunctionJsonConverter.cs:line 194
   at MakeFunctionJson.FunctionJsonConverter.TryRun() in /_/src/Microsoft.NET.Sdk.Functions.Generator/FunctionJsonConverter.cs:line 87
Error generating functions metadata
    SdBridge.FunctionHost   C:\Users\<<>>\.nuget\packages\microsoft.net.sdk.functions.0.1\build\Microsoft.NET.Sdk.Functions.Build.targets 32  

请提供解决此问题的任何指示 -

解决方法之一可以解决上述问题,

要将 Azure Function 3X 升级到 4X,我们需要在 .csproj 文件中添加以下内容

<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>

并将您的 Nuget package 更新为 "Microsoft.NET.Sdk.Functions" Version="4.0.1"

确保您已在本地安装 Azure function core tool version 4x

这是我尝试过的解决方法的详细信息

有关更多信息,请参阅此 MS 文档:Migrating from 3x to 4x