![](/img/trans.png)
[英]How to install Microsoft.Azure.Devices NuGet package for Unity?
[英]Unable to add Microsoft.Azure.Devices namespace to Azure Function run.csx
我有一个Azure函数,我需要从中通过IoT中心将消息发送回我的设备。 每当我尝试添加该语句时:
using Microsoft.Azure.Devices;
我收到以下错误:
run.csx(11,23):错误CS0234:类型或名称空间名称“设备”在名称空间“ Microsoft.Azure”中不存在(您是否缺少程序集引用?)
但是奇怪的是,错误提示,如果我只是using Microsoft.Azure
,就不会有编译错误。
因此,我尝试将设备与代码一起使用,例如static Devices.ServiceClient client;
,但同样是错误。
我也尝试使用#r "Microsoft.Azure.Devices
,但这也不起作用。
我尝试完全创建一个新的Function App服务,但是相同的错误不断弹出。
我的project.json文件看起来像这样:
{
"frameworks": {
"net47":{
"dependencies": {
"Microsoft.Azure.Devices": "1.4.1"
}
}
}
}
我也尝试过使用net46
。
我的应用程序的小描述:
因此,我的功能应该由ServiceBusTopic
触发,具有BlobStorage
作为输入。
由于不添加此名称空间,所以不知道如何将数据发送回设备。
以下是使用Microsoft.Azure.Devices nuget包的工作示例。 触发器是ServiceBusQueue , blobName是BrokeredMessage的应用程序属性。
run.csx:
using System;
using System.Text;
using System.Configuration;
using System.Threading.Tasks;
using Microsoft.Azure.Devices;
public static async Task Run(string inputMessage, string inputBlob, TraceWriter log)
{
log.Info($"C# ServiceBus queue trigger function processed message: {inputMessage}");
log.Info($"Blob:\n{inputBlob}");
string deviceId = "Device10";
var c2dmsg = new Microsoft.Azure.Devices.Message(Encoding.ASCII.GetBytes(inputMessage));
// create proxy
string connectionString = ConfigurationManager.AppSettings["myIoTHub2"];
var client = ServiceClient.CreateFromConnectionString(connectionString);
// send AMQP message
await client.SendAsync(deviceId, c2dmsg);
await client.CloseAsync();
}
function.json:
{
"bindings": [
{
"name": "inputMessage",
"type": "serviceBusTrigger",
"direction": "in",
"queueName": "function",
"connection": "myServiceBus",
"accessRights": "Manage"
},
{
"type": "blob",
"name": "inputBlob",
"path": "afstates/{Properties.blobName}",
"connection": "myStorage",
"direction": "in"
}
],
"disabled": false
}
project.json:
{
"frameworks": {
"net46":{
"dependencies": {
"Microsoft.Azure.Devices": "1.4.1"
}
}
}
}
请尝试以下步骤:
观察日志进度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.