简体   繁体   中英

Unable to compile Azure Function v4 out-of-process in VS 2022 Enterprise Version 17.0.0

The Azure Function's .csproj definition is per the following snippet:

<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>

The Program.cs file's initialization is like the following code snippet:

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();

The compiler issues the following error message:

Severity Code Description Project File Line Suppression State Error MSB4062 The "GenerateFunctionMetadata" task could not be loaded from the assembly C:\\Users\\myusername.nuget\\packages\\microsoft.net.sdk.functions\\4.0.1\\build..\\tools\\net6.0\\Microsoft.NET.Sdk.Functions.MSBuild.dll. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. MyApp.Functions C:\\Users\\myusername.nuget\\packages\\microsoft.azure.functions.worker.sdk\\1.3.0\\build\\Microsoft.Azure.Functions.Worker.Sdk.targets 60

Would you please give a direction on fixing this problem?

我们需要删除 Microsoft.NET.Sdk.Functions NuGet 包引用来解决这个编译问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM