【发布时间】:2018-01-17 15:06:40
【问题描述】:
我正在尝试创建一个 Azure 函数,它将在 macOS 中使用 VSCode 由 HTTP 触发。
使用官方documentation,我在本地机器上成功创建了一个HTTP Trigered azure函数。
现在我想在这个函数期间发送一封电子邮件,但是当我添加一个 senGrid 引用时,我得到了一个编译错误:
以下1个函数有误: [15/01/2018 21:51:12] ResetPasswordSendEmail:C# 编译服务错误:无法加载文件或程序集“SendGrid,Culture=neutral,PublicKeyToken=null”。该系统找不到指定的文件。 [15/01/2018 21:51:12]。无法加载文件或程序集“SendGrid,Culture=neutral,PublicKeyToken=null”。系统找不到指定的文件。
天蓝色功能:
#r "SendGrid"
#r "Newtonsoft.Json"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using SendGrid.Helpers.Mail;
public static IActionResult Run(HttpRequest req, TraceWriter log, out Mail message)
{
log.Info("C# HTTP trigger function processed a request.");
string requestBody = new StreamReader(req.Body).ReadToEnd();
dynamic data = JsonConvert.DeserializeObject(requestBody);
string email = data.email;
string password = data.password;
message = new Mail
{
Subject = "Azure news"
};
bool isOk = !string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(password);
return isOk ? req.CreateResponse(HttpStatusCode.OK) : req.CreateResponse(HttpStatusCode.BadRequest, "EmailError");
}
json函数:
{
"disabled": false,
"bindings": [{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in"
},
{
"name": "message",
"type": "sendGrid",
"direction": "out",
"apiKey": "AzureWebJobsSendGridApiKey"
},
{
"name": "$return",
"type": "http",
"direction": "out"
}
]
}
我想将代码保留在同一位置,并且没有代码管理 (GIT) 之外的 azure 函数。
如果有人知道如何解决我的问题,请帮助:D
【问题讨论】:
-
我觉得你需要参考NuGet包
Microsoft.Azure.WebJobs.Extensions.SendGrid -
在哪里?我没有看到任何 csproj 并且手动添加 project.json 不能解决问题
标签: c# azure azure-functions