无法在VS 2022 Enterprise Version 17.0.0中编译进程外的Azure Function v4



Azure函数的.csproj定义如下:

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10.0</LangVersion>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.6.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.3.0" OutputItemType="Analyzer" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.1.0" />
</ItemGroup>

Program.cs文件的初始化类似于以下代码片段:

var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureAppConfiguration((context, configure) =>
{
configure
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{context.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables();
})
.ConfigureServices((context, services) =>
{
services.AddMyServices();
})
.Build();

编译器发出以下错误消息:

严重性代码描述项目文件行禁止显示状态错误MSB4062";GenerateFunctionMetadata";无法从程序集C:\Users\myusername.nuget\packages\microsoft.net.sdk.functions\4.0.1\build..\tools\net6.0\MMicrosoft.net.sdk.functions.MSBuild.dll加载任务。请确认声明正确,程序集及其所有依赖项可用,并且任务包含实现microsoft的公共类。建筑框架ITask。MyApp。函数C:\Users\myusername.nuget\packages\microsoft.azure.Functions.worker.sdk\1.3.0\build\microsoft.azure.Functions.worker.sdk.targets 60

你能告诉我如何解决这个问题吗?

我们需要删除Microsoft。NET。Sdk。函数NuGet包引用以解决此编译问题。

最新更新