.net - 面向 .net 4.7.1 的项目无法引用依赖于 .net standard 2.0 的 NuGet 包

标签 .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 项目中?

最佳答案

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 applications and web sites don't support automatic binding redirect generation. In order to resolve binding conflicts, you need to double click the warning in the error list and Visual Studio will add them to your web.config file.

关于.net - 面向 .net 4.7.1 的项目无法引用依赖于 .net standard 2.0 的 NuGet 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49326134/

相关文章:

.net - Monotouch命令行构建不起作用

.net - SpecRun.SpecFlow 1.2.0 与 UAP 不兼容,Version=v10.0

visual-studio - 防止需要将 NuGet.exe 添加到源代码管理

c - 在 visual studio 2013 中 ctrl/f7 不起作用

c++ - 检测动态链接到 FFMPEG 的 C++ 代码时出现警告 VSP2005 和错误 VSP1048

c# - 可访问性不一致 : field type 'System. Collections.Generic.Dictionary<> 的可访问性低于其他字段

nuget - 防止 nuget 包修改

c# - 如何将多个 bool 值声明为 false

c# - 在 ExecuteNonQuery 上获取受影响的行

vb.net - IO.File.Copy 是否复制文件属性?