Azure Function 2 - 缺少 using 指令或程序集引用?

Azure Function 2 - missing a using directive or an assembly reference?

我使用 Visual Studio 2017 创建了我的 Azure Function v2。

我创建了一个新的队列触发器函数。

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace Functions
{
    public static class queue
    {
        [FunctionName("queue")]
        public static void Run([QueueTrigger("myqueue-items", Connection = "test")]string myQueueItem, ILogger log)
        {
            log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
        }
    }
}

但是找不到QueueTrigger的程序集

Error   CS0246  The type or namespace name 'QueueTriggerAttribute' could not be found (are you missing a using directive or an assembly reference?)
Error   CS0246  The type or namespace name 'QueueTrigger' could not be found (are you missing a using directive or an assembly reference?)
Error   CS0246  The type or namespace name 'Connection' could not be found (are you missing a using directive or an assembly reference?)

正如 Nkosi 所说,您可以前往 Azure Queue storage bindings for Azure Functions 检查您是否配置了绑定扩展。

关于您的信息,我认为您需要安装 Microsoft.Azure.WebJobs.Extensions.Storage NuGet 包,版本 3.x。那么一切都会好起来的。

我使用 cli 工具在 Visual studio 代码中创建了一个队列触发器函数。它在 host.json 文件中创建了 2.0 版的 azure 函数。当我 运行 该函数时,我得到了同样的错误。我可以通过在 .csproj 文件中添加以下行来解决此问题。

<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.24" />