【问题标题】:Unable to debug Azure Function that targets .NET 5.0无法调试面向 .NET 5.0 的 Azure 函数
【发布时间】:2021-08-06 04:45:36
【问题描述】:

我使用 .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 隔离进程”模型有关还是我做错了什么?

【问题讨论】:

  • 查看this blog post - Dave 在“关于工具”段落中解释说,该工具与 .NET Core 3.x 版本并不完全一致。您可以在本地调试 - 让它工作需要更多的参与
  • 可能重复(关于如何解决限制的答案):stackoverflow.com/q/67526631/1149773

标签: visual-studio azure-functions .net-5


【解决方案1】:

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

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

  2. 使用“func start --dotnet-isolated-debug”在 shell 中运行函数;

  3. 在窗口中显示的PID处附加调试器

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2019-09-29
  • 1970-01-01
  • 2020-05-19
  • 2018-04-29
  • 1970-01-01
  • 2023-04-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多