c# - 无法在 VS 2022 Enterprise 版本 17.0.0 中编译 Azure Function v4 进程外

标签 c# visual-studio azure-functions

Azure Function 的 .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();

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

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

您能否给出解决此问题的指导?

最佳答案

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

关于c# - 无法在 VS 2022 Enterprise 版本 17.0.0 中编译 Azure Function v4 进程外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69889911/

相关文章:

c# - Powerpoint 中形状的部分下划线检查不起作用?

C#如何判断一个数是不是另一个数的倍数?

c# - 动态数据 Web 应用程序给我错误?

c++ - 在 Visual Studio Debug模式下编译的可执行文件 : jmp to function body instead of direct address in call

c - 如何从 Visual Studio C 编译器获得更有用的警告?

python - 如何在 python Azure 函数中使用 ZBar 库?

azure - 如何从azure功能将消息添加到azure服务总线?

c# - C# 上 mysql 语法的输入参数

c++ - 从 DLL 导出全局变量

azure-functions - OpenApiExample 未显示在 swagger UI 中