我有一个面向 .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/