如何在本地调试 azure 函数

How do I debug azure function locally

您好,我在 Azure 门户中创建了一个函数,并看到队列数据已出列。

我在计算机上安装了 CLI,当我 运行 项目时,它将显示 func.exe 命令提示符。我在 local.settings.json:

中添加了这样的连接字符串
>  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=...",
    "AzureWebJobsDashboard": "DefaultEndpointsProtocol=https;AccountName=...",
    "tuxdev_STORAGE": "DefaultEndpointsProtocol=https;AccountName=..."
  } 

当我将消息添加到门户中的队列时,应用程序没有收到消息。我还需要更新哪些其他设置。

根据您的错误消息,问题似乎出在您的 class 或方法上,而不是 public。如果我将我的方法设置为私有,我也会得到与您相同的错误。

如果我将函数方法设置为public,一切正常。该函数将显示我在门户中添加的队列。

using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;

 public static class Function1
{
    [FunctionName("Function1")]
    public static void Run([QueueTrigger("myqueue", Connection = "AzureWebJobsStorage")]string myQueueItem, TraceWriter log)
    {

        log.Info($"C# Queue trigger function processed: {myQueueItem}");
    }
}

或者问题可能与您的 nuget 包版本有关。您可以升级到最新的 Microsoft.NET.Sdk.Functions(截至今天的 1.0.6)和 Microsoft.Azure.WebJobs.Service.Bus(如果 运行 在完整框架上,则为 2.1.0-beta4)。请参考这个.

You should upgrade to the latest Microsoft.NET.Sdk.Functions (1.0.6 as of today) and Microsoft.Azure.WebJobs.Service.Bus (2.1.0-beta4 if running on full framework). You might need to remove ServiceBus reference first in order to upgrade SDK.

The Microsoft.Azure.Eventhubs package also needs to be removed. All relevant types etc are in Microsoft.Azure.WebJobs.Service.Bus

Also remember to check "Include prerelease" in the package manager in order to find 2.1.0-beta4