簡體   English   中英

無法在C#Azure函數中使用Nuget程序包

[英]Can't use Nuget package in C# Azure function

我正在嘗試編寫一個將使用Sendgrid發送電子郵件的Azure函數。 但是,我無法識別外部nuget包。 這是我所擁有的:

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("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?)

我想念什么?

如果確實在v1運行時上,那么您只是缺少具有EmailAddress類型的using語句。

將此添加到—

using SendGrid.Helpers.Mail;

如果您使用的是v2(測試版/.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上運行應該沒有問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM