EventHubTriggerAttribute 在命名空间 'Microsoft.Azure.WebJobs' 中不存在
EventHubTriggerAttribute does not exists in namespace 'Microsoft.Azure.WebJobs'
采取以下步骤在 Visual Studio
中创建 Azure 函数
- 创建新项目并选择
Azure Function
模板
- Select Azure Function V2(.net 代码)和
IoT Hub Trigger
代码已生成但有引用错误。
using IoTHubTrigger = Microsoft.Azure.WebJobs.EventHubTriggerAttribute;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.EventHubs;
using System.Text;
using System.Net.Http;
using Microsoft.Extensions.Logging;
namespace DeviceMessageFunction_v2
{
public static class Function1
{
private static HttpClient client = new HttpClient();
[FunctionName("Function1")]
public static void Run([IoTHubTrigger("messages/events", Connection = "")]EventData message, ILogger log)
{
log.LogInformation($"C# IoT Hub trigger function processed a message: {Encoding.UTF8.GetString(message.Body.Array)}");
}
}
}
CS0234 The type or namespace name 'EventHubTriggerAttribute' does not exist in the namespace 'Microsoft.Azure.WebJobs' (are you missing an assembly reference?) DeviceMessageFunction_v2 C:\Functions\DeviceMessageFunction_v2\Function1.cs
尝试添加引用,但没有成功
这是我的工具和框架的详细信息
- 微软 Visual Studio 企业版 2017
- 版本 15.7.4
- 微软 .NET 框架
- 版本 4.7.02558
- 已安装版本:Enterprise
- Azure 应用服务工具 v3.0.0 15.0.40608.0
- Azure 函数和 Web 作业工具 15.9.02046.0
使用 V2 函数时需要使用额外的 NuGet 包,Microsoft.Azure.WebJobs.Extensions.EventHubs
(Source)
采取以下步骤在 Visual Studio
中创建 Azure 函数- 创建新项目并选择
Azure Function
模板
- Select Azure Function V2(.net 代码)和
IoT Hub Trigger
代码已生成但有引用错误。
using IoTHubTrigger = Microsoft.Azure.WebJobs.EventHubTriggerAttribute; using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Host; using Microsoft.Azure.EventHubs; using System.Text; using System.Net.Http; using Microsoft.Extensions.Logging; namespace DeviceMessageFunction_v2 { public static class Function1 { private static HttpClient client = new HttpClient(); [FunctionName("Function1")] public static void Run([IoTHubTrigger("messages/events", Connection = "")]EventData message, ILogger log) { log.LogInformation($"C# IoT Hub trigger function processed a message: {Encoding.UTF8.GetString(message.Body.Array)}"); } } }
CS0234 The type or namespace name 'EventHubTriggerAttribute' does not exist in the namespace 'Microsoft.Azure.WebJobs' (are you missing an assembly reference?) DeviceMessageFunction_v2 C:\Functions\DeviceMessageFunction_v2\Function1.cs
尝试添加引用,但没有成功
这是我的工具和框架的详细信息
- 微软 Visual Studio 企业版 2017
- 版本 15.7.4
- 微软 .NET 框架
- 版本 4.7.02558
- 已安装版本:Enterprise
- Azure 应用服务工具 v3.0.0 15.0.40608.0
- Azure 函数和 Web 作业工具 15.9.02046.0
使用 V2 函数时需要使用额外的 NuGet 包,Microsoft.Azure.WebJobs.Extensions.EventHubs
(Source)