.NET STandard 2.0:将目标框架更改为.net 4.7.2

时间:2018-07-23 16:12:23

标签: c# nuget .net-standard nuget-package-restore .net-framework-version

我刚刚将我们的几个项目从.net Framework 4.6.2更新到了.net Framework 4.7.2,并且出现以下错误:

Package Microsoft.AspNetCore 2.1.2 is not compatible with net472 (.NETFramework,Version=v4.7.2). Package Microsoft.AspNetCore 2.1.2 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.AspNetCore.Authentication.Cookies 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2). Package Microsoft.AspNetCore.Authentication.Cookies 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.AspNetCore.Authentication.JwtBearer 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2). Package Microsoft.AspNetCore.Authentication.JwtBearer 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.AspNetCore.Cors 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2). Package Microsoft.AspNetCore.Cors 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.AspNetCore.Identity.EntityFrameworkCore 2.1.2 is not compatible with net472 (.NETFramework,Version=v4.7.2). Package Microsoft.AspNetCore.Identity.EntityFrameworkCore 2.1.2 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.AspNetCore.Mvc 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2). Package Microsoft.AspNetCore.Mvc 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.AspNetCore.StaticFiles 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2). Package Microsoft.AspNetCore.StaticFiles 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.EntityFrameworkCore.SqlServer 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2). Package Microsoft.EntityFrameworkCore.SqlServer 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.EntityFrameworkCore.Tools 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2). Package Microsoft.EntityFrameworkCore.Tools 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.Extensions.Configuration.UserSecrets 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2). Package Microsoft.Extensions.Configuration.UserSecrets 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.Extensions.Logging.Debug 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2). Package Microsoft.Extensions.Logging.Debug 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.VisualStudio.Web.BrowserLink 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2). Package Microsoft.VisualStudio.Web.BrowserLink 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2). Package Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.EntityFrameworkCore.Relational 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2). Package Microsoft.EntityFrameworkCore.Relational 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.VisualStudio.Web.CodeGenerators.Mvc 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2). Package Microsoft.VisualStudio.Web.CodeGenerators.Mvc 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    One or more packages are incompatible with .NETFramework,Version=v4.7.2.
    Package Microsoft.AspNetCore 2.1.2 is not compatible with net472 (.NETFramework,Version=v4.7.2) / win7-x86. Package Microsoft.AspNetCore 2.1.2 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.AspNetCore.Authentication.Cookies 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2) / win7-x86. Package Microsoft.AspNetCore.Authentication.Cookies 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.AspNetCore.Authentication.JwtBearer 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2) / win7-x86. Package Microsoft.AspNetCore.Authentication.JwtBearer 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.AspNetCore.Cors 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2) / win7-x86. Package Microsoft.AspNetCore.Cors 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2) / win7-x86. Package Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.AspNetCore.Identity.EntityFrameworkCore 2.1.2 is not compatible with net472 (.NETFramework,Version=v4.7.2) / win7-x86. Package Microsoft.AspNetCore.Identity.EntityFrameworkCore 2.1.2 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.AspNetCore.Mvc 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2) / win7-x86. Package Microsoft.AspNetCore.Mvc 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.AspNetCore.StaticFiles 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2) / win7-x86. Package Microsoft.AspNetCore.StaticFiles 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.EntityFrameworkCore.SqlServer 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2) / win7-x86. Package Microsoft.EntityFrameworkCore.SqlServer 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.EntityFrameworkCore.Tools 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2) / win7-x86. Package Microsoft.EntityFrameworkCore.Tools 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.Extensions.Configuration.UserSecrets 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2) / win7-x86. Package Microsoft.Extensions.Configuration.UserSecrets 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.Extensions.Logging.Debug 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2) / win7-x86. Package Microsoft.Extensions.Logging.Debug 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.VisualStudio.Web.BrowserLink 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2) / win7-x86. Package Microsoft.VisualStudio.Web.BrowserLink 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.EntityFrameworkCore.Relational 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2) / win7-x86. Package Microsoft.EntityFrameworkCore.Relational 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    Package Microsoft.VisualStudio.Web.CodeGenerators.Mvc 2.1.1 is not compatible with net472 (.NETFramework,Version=v4.7.2) / win7-x86. Package Microsoft.VisualStudio.Web.CodeGenerators.Mvc 2.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)
    One or more packages are incompatible with .NETFramework,Version=v4.7.2 (win7-x86).

真正让我感到困惑的是.NETFramework 4.7.2与.NET Standard 2.0兼容,那么为什么我们会收到此错误消息?没道理! 任何帮助表示赞赏。

3 个答案:

答案 0 :(得分:2)

我在CI服务器上遇到了这个问题,原来是安装了nuget.exe的较旧副本,将其升级到最新版本已解决了该问题(从v4.1到4.7)

答案 1 :(得分:0)

在称为VSTS的AzureDevOps中对我有用的解决方案:

1-添加一个dotnet恢复步骤。

2-在Nuget Restore步骤的高级选项中,选择自定义版本,然后将“ Nutget.exe的路径”设置为:$(Build.BinariesDirectory)\ nuget.exe

3-在NuGet恢复任务之前添加内联PowerScript shell,请参阅以下github链接: https://github.com/Microsoft/vsts-tasks/issues/3756#issuecomment-288185011

别忘了将Shell脚本中的nuget版本更改为您想要的版本(对我来说是4.3.0)。

答案 2 :(得分:-3)

将您的NuGet安装程序更新为版本2. *。之后,NuGet.exe将自动更新到版本4.3