我无法在 Visual Studio 代码中调试我的 azure 函数

问题描述 投票:0回答:1

我在本地运行 azure 函数时遇到以下问题

未找到工作职能。尝试公开您的工作类别和方法。如果您使用绑定扩展(例如 Azure 存储、ServiceBus、定时器等),请确保您已在启动代码中调用扩展的注册方法(例如 builder.AddAzureStorage()、builder.AddServiceBus( )、builder.AddTimers() 等)。

这到底意味着什么

我使用下面的链接创建了基本的 C# http 触发函数

https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-csharp

Azure 函数运行用于本地开发

c# .net azure azure-functions
1个回答
0
投票

我创建了一个

dotnet-isolated
Azure 函数,可以按预期调试和运行。

遵循的步骤:

  • 创建了.NET隔离的Http触发功能。

local.settings.json:

  • 确保您已添加设置
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
  }
}

主机.json:

{
    "version": "2.0",
    "logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            },
            "enableLiveMetricsFilters": true
        }
    }
}
  • .csproj 中安装的软件包:
<ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.1" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.1.0" />
  </ItemGroup>

函数.cs:

public class HttpTriggerCSharp1
    {
        private readonly ILogger<HttpTriggerCSharp1> _logger;

        public HttpTriggerCSharp1(ILogger<HttpTriggerCSharp1> logger)
        {
            _logger = logger;
        }

        [Function("HttpTriggerCSharp1")]
        public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req)
        {
            _logger.LogInformation("C# HTTP trigger function processed a request.");
            return new OkObjectResult("Welcome to Azure Functions!");
        }
    }

程序.cs:

using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .ConfigureServices(services => {
        services.AddApplicationInsightsTelemetryWorkerService();
        services.ConfigureFunctionsApplicationInsights();
    })
    .Build();

host.Run();
  • 使用F5调试功能:

enter image description here

  • 能够成功运行该功能:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.