1

我正在尝试编写一个将使用 Sendgrid 发送电子邮件的天蓝色函数。但是,我无法让我的功能识别外部 nuget 包。这是我所拥有的:

项目.json

{
"frameworks": {
    "net46": {
        "dependencies": {
            "SendGrid": "9.9.0"
        }
    }
  }
}

运行.csx:

using System;
using Sendgrid;

public static void Run(TimerInfo myTimer, TraceWriter log)
{
    var client = new SendGridClient("xxx");
    var fromAddr = new EmailAddress("xxx@xxx.com", "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?)

我错过了什么?

4

1 回答 1

3

如果您确实在 v1 运行时,那么您只是缺少具有该EmailAddress类型的 using 语句。

添加这个 -

using SendGrid.Helpers.Mail;

如果您使用的是 v2(beta/.NET Core),只需从评论中关注kim的 URL(您需要一个function.proj代替)-

<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 上运行应该没有问题。

于 2018-04-12T20:30:38.523 回答