在 Visual Studio 中调试 Azure 函数

Debug Azure Function in Visual Studio

我最初将我的 Azure 函数创建为与 dotnet 5 隔离的 dotnet。不幸的是,由于 this issue 我不得不将它降级到进程内和 dotnet 核心 3.1。

我的问题是 VS 似乎不知道它是一个函数应用程序。它被设置为启动项目,但是当我按 F5 进行调试时,我收到消息:

A project with an Output Type of Class Library cannot be started directly

cs proj文件内容如下:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
      <Nullable>enable</Nullable>
      <UserSecretsId>...</UserSecretsId>
  </PropertyGroup>

  <ItemGroup>
    <None Remove="local.settings.json" />
  </ItemGroup>

  <ItemGroup>
    <Content Include="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
    etc...
  </ItemGroup>

  <ItemGroup>
    <ProjectReference...
  </ItemGroup>

  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

</Project>

有人知道 VS 使用什么来决定库应该 运行 作为函数应用程序吗?

问题是缺少对 Microsoft.NET.Sdk.Functions 的包引用。一旦我将以下内容添加到 csproj 文件中,我就可以调试了:

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