无法调试面向 .NET 5.0 的 Azure 函数

Unable to debug Azure Function that targets .NET 5.0

我使用 .NET CORE 3.1 作为目标框架从模板编写了一个简单的 Azure 函数。

之后,我使用 guide

将目标框架迁移到 .NET 5.0

迁移后我无法调试 Azure 函数。我收到通常的消息“当前不会命中断点”。

csproj 是这样的:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.2.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.0.3" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

local.settings.json是这样的:

{
    "IsEncrypted": false,
    "Values": {
      "AzureWebJobsStorage": "UseDevelopmentStorage=true",
      "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
  }
}

program.cs是这样的:

class Program
{
    static Task Main(string[] args)
    {
        var host = new HostBuilder()
                        .ConfigureFunctionsWorkerDefaults()
                        .ConfigureServices(s =>
                        {
                        })
                        .Build();

        return host.RunAsync();
    }
}

简单函数为:

using System.Threading.Tasks;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;

namespace FunctionAppNet50
{
    public static class Function1
    {
        [Function("Function1")]
        public static async Task<HttpResponseData> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req)
        {
            var response = req.CreateResponse(System.Net.HttpStatusCode.OK);

            return response;
        }
    }
}

这与“.NET 隔离进程”模型有关还是我做错了什么?

谢谢...在 marc_c 和 Douglas 推荐的文章中找到了解决方案。

  1. 我使用 choco 通过命令“choco install azure-functions-core-tools-3”安装了 Azure Function Core Tools;

  2. 运行 shell 中的函数 with "func start –-dotnet-isolated-debug";

  3. 在 window

    中显示的 PID 处附加调试器

这是一篇类似步骤的文章:https://dev.to/kenakamu/debug-net-5-function-with-visual-studio-visual-studio-code-5235