问题描述
我正在尝试编写一个将使用Sendgrid发送电子邮件的天蓝色函数.但是,我无法获得识别外部nuget包的功能.这就是我所拥有的:
I'm trying to write an azure function which will use Sendgrid to send emails. However, I can't get my function to recognize the external nuget package. Here's what I have:
project.json
project.json
{
"frameworks": {
"net46": {
"dependencies": {
"SendGrid": "9.9.0"
}
}
}
}
run.csx:
using System;
using Sendgrid;
public static void Run(TimerInfo myTimer, TraceWriter log)
{
var client = new SendGridClient("xxx");
var fromAddr = new EmailAddress("[email protected]", "xxx");
var toAddr = new EmailAddress("xxxx", "xxx);
var msg = MailHelper.CreateSingleEmail(fromAddr, toAddr, "subject", "content", "content");
client.SendEmailAsync(msg).Wait();
}
我收到此错误:
[Error] run.csx(8,7): error CS0246: The type or namespace name 'Sendgrid' could not be found (are you missing a using directive or an assembly reference?)
我想念什么?
推荐答案
如果您确实在v1运行时中,那么您只是缺少类型为EmailAddress
的using语句.
If you are indeed on the v1 runtime then you're simply missing a using statement that has the EmailAddress
type.
在—
using SendGrid.Helpers.Mail;
如果您使用的是v2(测试版/.NET Core),则只需从注释中跟随 kim 的URL(您将需要用function.proj
代替) —
If you're on v2 (beta/.NET Core), just follow kim's URL from comments (you'll need a function.proj
instead) —
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SendGrid" Version="9.9.0"/>
</ItemGroup>
</Project>
SendGrid NuGet包以 .NET Standard 1.3 为目标,因此在.NET Core上运行应该没有问题.
The SendGrid NuGet package targets .NET Standard 1.3, so running on .NET Core should pose no problem.
这篇关于无法在C#Azure函数中使用Nuget程序包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!