【问题标题】:Error while installing package in ASP.NET core app在 ASP.NET 核心应用程序中安装包时出错
【发布时间】:2017-05-29 20:30:17
【问题描述】:

我正在使用 VS 2017 创建 ASP.NET Core Web 应用程序。安装 Sendgrid 包时,出现以下错误。

包 Sendgrid 8.0.5 与 netcoreapp1.0 (.NETCoreApp,Version=v1.0) 不兼容。包 Sendgrid 8.0.5 支持:net (.NETFramework,Version=v0.0) 包 Microsoft.AspNet.WebApi.Client 5.2.3 与 netcoreapp1.0 (.NETCoreApp,Version=v1.0) 不兼容。包 Microsoft.AspNet.WebApi.Client 5.2.3 支持: net45 (.NETFramework,版本=v4.5) 便携-net45+netcore45+wp8+wp81+wpa81(.NETPortable,版本=v0.0,配置文件=wp8+netcore45+net45+wp81+wpa81) 包 SendGrid.CSharp.HTTP.Client 3.0.0 与 netcoreapp1.0 (.NETCoreApp,Version=v1.0) 不兼容。包 SendGrid.CSharp.HTTP.Client 3.0.0 支持:net (.NETFramework,Version=v0.0) 一个或多个包与 .NETCoreApp 不兼容,Version=v1.0。`

这个错误有什么解决办法吗?

【问题讨论】:

  • 能否请您发布您的 project.json 文件。

标签: asp.net asp.net-core sendgrid visual-studio-2017


【解决方案1】:

您可能需要使用预发布版本。

https://www.nuget.org/packages/SendGrid.NetCore/

【讨论】:

    【解决方案2】:

    该错误为您提供了 SendGrid 8.0.5 及其依赖项的支持矩阵。

                                    net     net45   portable-net45+netcore45+wp8+wp81+wpa81
    SendGrid                         1
    Microsoft.AspNet.WebApi.Client            1             1
    SendGrid.CSharp.HTTP.Client      1
    

    您可以看到它们都不支持核心框架 (netcoreapp),而是需要完整框架 (net)。

    如果您要求您的应用在 Core Framework 上运行,则不能使用 SendGrid 8.0.5。您的选择包括(但不限于)使用SendGrid.NetCore 或使用MailKit

    如果您不要求您的应用在 Core Framework 上运行并且可以仅支持完整框架 (net),那么您可以使用 SendGrid 8.0.5。

    对于我们自己的应用程序,我们选择使用MailKit 版本1.10.0,因为它比SendGrid.NetCore 更成熟,并且它支持核心框架。我们使用它如下:

    项目.json

    "dependencies": {                                                        
        "MailKit": "1.10.0"                                                  
    },                                                                       
    "frameworks": {                                                          
        "netcoreapp1.1": {}                                                  
    }
    

    使用带有 MailKit 的 SendGrid 发送电子邮件。

    var mimeMessage = new MimeMessage();
    mimeMessage.From.Add(new MailboxAddress("Admin", "admin@mailbox.com"));
    mimeMessage.To.Add(new MailboxAddress("Jon Doe", "jon@doe.com"));
    mimeMessage.Subject = "An Email for You!";
    mimeMessage.Body = new TextPart("html")
    {
        Text = "This is the message.";
    };
    
    using (var client = new SmtpClient())
    {
        client.ServerCertificateValidationCallback = (s, c, h, e) => true;
        client.Connect("smtp.sendgrid.net", 587);
        await client.AuthenticateAsync("myuser@foobar.com", "ASD43234GDX");    
        await client.SendAsync(mimeMessage);
        client.Disconnect(true);  
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-12
      • 2018-11-29
      • 2018-12-24
      • 2010-10-31
      • 2019-09-08
      相关资源
      最近更新 更多