针对.net 4.7.1的项目无法引用依赖于.net标准2.0的NuGet包

时间:2018-03-16 17:07:56

标签: .net visual-studio nuget

我有一个针对.net 4.7.1的ASP .Net项目。我正在尝试添加the Microsoft.AspNetCore.DataProtection package(取决于.net标准2.0)。

I thought .net 4.7.1 is part of the .net standard 2.0,但当我尝试添加此软件包时,NuGet告诉我以下内容。

Attempting to gather dependency information for package 'Microsoft.AspNetCore.DataProtection.2.0.2' with respect to project 'IssueCenter.Website', targeting '.NETFramework,Version=v4.7.1'
Gathering dependency information took 239,47 ms
Attempting to resolve dependencies for package 'Microsoft.AspNetCore.DataProtection.2.0.2' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'Microsoft.AspNetCore.DataProtection.2.0.2'
Resolved actions to install package 'Microsoft.AspNetCore.DataProtection.2.0.2'
Retrieving package 'Microsoft.AspNetCore.DataProtection 2.0.2' from 'NuGet official package source'.
  GET https://www.nuget.org/api/v2/package/Microsoft.AspNetCore.DataProtection/2.0.2
  OK https://www.nuget.org/api/v2/package/Microsoft.AspNetCore.DataProtection/2.0.2 291ms
Installing Microsoft.AspNetCore.DataProtection 2.0.2.
Install failed. Rolling back...
Package 'Microsoft.AspNetCore.DataProtection.2.0.2' does not exist in project 'IssueCenter.Website'
Package 'Microsoft.AspNetCore.DataProtection.2.0.2' does not exist in folder 'D:\projetos\IssueCenter\DotNet\IssueCenter2.DotNet\packages'
Executing nuget actions took 984,59 ms
Could not install package 'Microsoft.AspNetCore.DataProtection 2.0.2'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.7.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
Time Elapsed: 00:00:01.4162507
========== Finished ==========

它发生在Visual Studio 2012和Visual Studio 2017上。

Microsoft Visual Studio Community 2017  15.0.26228.4 D15RTWSVC

Microsoft .NET Framework                4.7.02556

NuGet Package Manager                   4.0.0

如何将Microsoft.AspNetCore.DataProtection包添加到.net 4.7.1项目中?

1 个答案:

答案 0 :(得分:3)

在VS 15.3中添加了NetStandard 2.0支持,您的15.0 RTW版本将无法安装.NET Standard 2.0软件包。

使用.NET Standard程序集时,您可能会遇到(经典)ASP.NET应用程序中的问题。检查dotnet/Announcements GitHub issue on this topic,具体来说:

  

Web应用程序和网站不支持自动绑定   重定向生成。为了解决绑定冲突,您需要   双击错误列表中的警告,Visual Studio将   将它们添加到您的web.config文件中。