如何解决.net Core构建错误NETDSDK1061和警告MSB3277 [英] How to resolve .net core build error NETDSDK1061 and warning MSB3277

查看:672
本文介绍了如何解决.net Core构建错误NETDSDK1061和警告MSB3277的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,就是我的AspNetCore.App-metapackage引用的EntityFrameworkCore(2.1.2)版本低于EfCore提供程序的软件包(NpgSql,引用2.1.3)。结果是警告MSB3277(



我在类库项目中遇到了Microsoft.NETCore.App的相同问题



我什至没有注意到我使用了比可用的旧的元软件包。直到今天,我始终检查NuGet软件包管理器中是否有任何更新。我已经使用了默认的项目模板,并始终安装了最新的.NetCore SDK,以为这就足够了。



调查此问题之后,我发现我可以强制我的项目使用特定的.NETCore.App或AspNetCore.App元包使用软件包管理器控制台( Install-Package Microsoft.NETCore.App -Version 2.1.4 Install-Package Microsoft.AspNetCore.App -Version 2.1。 4 )。



该命令之后,我发生了构建错误( NETSDK1061:使用Microsoft还原了该项目.NETCore.App版本2.1.4,但使用当前设置,而是使用版本2.1.0。要解决此问题,请确保将相同的设置用于还原以及后续操作(如生成或发布)。)。

解决方案

我试图找到有关该问题的帮助,找到了一些github问题(例如这一个)看上去很相似,但实际上却有所不同。
我找到了描述性文档,但这并没有真正帮助我。



我找到了非常有帮助的博客帖子(来自Rick Strahl),解释了可用的软件包以及每个包装的目的是什么。



这是我的解决方案:



步骤1:
执行安装软件包Microsoft.AspNetCore.App -Version [VersionOfYourChoice] 和/或执行安装软件包Microsoft.NETCore.App -Version [VersionOfYourChoice] 在软件包管理器控制台中。



步骤2:
如下所示编辑.csproj:

 < PropertyGroup> 
< TargetFramework> netcoreapp2.1< / TargetFramework>
< RuntimeFrameworkVersion> 2.1.4< / RuntimeFrameworkVersion> <-添加此行
<!-< TargetLatestRuntimePatch> true< / TargetLatestRuntimePatch> -> <-替代
< / PropertyGroup>

另外一点:如果您使用Win10,请帮自己一个忙,检查安装的.Net Core SDK /运行时等。卸载您不需要的每个SDK /运行时(再次:查看Ricks博客文章)。
您只需要在一个项目中当前定位的目标。



例如:如果您正在开发一个.NETCore项目,而您刚刚在2.1.4版中完成了这两个步骤-在撰写本文时,您只需要Microsoft .NET Core SDK 2.1.402。为了稍微整理一下,我卸载了每个.NET Core SDK / Runtimes / Packages,并从此处



注意:我关注了这是Jeff Atwood的博客文章,它回答了一个问题,这使我花了很长时间才解决。希望对您有所帮助...



编辑
.NET Core 2.2 的好消息:您只需要按如下方式编辑.csproj:

 < PropertyGroup> 
< TargetFramework> netcoreapp2.2< / TargetFramework>
< RuntimeFrameworkVersion> 2.2.0< / RuntimeFrameworkVersion>
< / PropertyGroup>

编辑
元软件包不再应该手动更新。 这是有关更新AspNetCore的建议。元软件包的版本取决于安装的SDK。


I´ve had the problem, that my AspNetCore.App-metapackage referenced a lower Version of EntityFrameworkCore (2.1.2), than a EfCore provider package (NpgSql, referencing 2.1.3). The result was the warning MSB3277 (here is the question). The quickfix for that was the accepted answer.

Another answer pointed out, that I´ve worked with a lower Microsoft.AspNetCore.App package (2.1.1 at that time) than the last stable version (2.1.4). Changing the package Version was not possible (see picture below).

I´ve had the same issue with Microsoft.NETCore.App in a class library-project

I even didn´t noticed that I used an older metapackage than available. Until today I always checked, if any Updates are available in NuGet Package Manager. I´ve worked with the default project templates and always installed the latest .NetCore SDKs, believing that this is enough. It wasn´t.

After investigating this issue, I´ve found out, that I can force my project to use a specific .NETCore.App or AspNetCore.App metapackage with package manager console (Install-Package Microsoft.NETCore.App -Version 2.1.4 or Install-Package Microsoft.AspNetCore.App -Version 2.1.4).

After that command I´ve had a build error (NETSDK1061: The project was restored using Microsoft.NETCore.App version 2.1.4, but with current settings, version 2.1.0 would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish.).

解决方案

I´ve tried to find any help on that issue, finding some github-issues (e.g. this one) looking pretty similar, but where actually different. I´ve found a descriptive doc, but that didn´t really helped me.

I found a pretty helpful blogpost from Rick Strahl, explaining what packages are available and what the purpose of each package is. That was a good thing to start.

This is my solution:

Step 1: Execute Install-Package Microsoft.AspNetCore.App -Version [VersionOfYourChoice] and/or execute Install-Package Microsoft.NETCore.App -Version [VersionOfYourChoice] in package manager console.

Step 2: Edit .csproj as shown below:

<PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <RuntimeFrameworkVersion>2.1.4</RuntimeFrameworkVersion>  <- add this line
    <!--<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch> --> <- alternative
</PropertyGroup>

One more takeaway: If you work with Win10, do yourself a favor and check the installed .Net Core SDK/Runtimes etc. Uninstall every SDK/Runtimes you do not need (again: Check Ricks blogpost for that). You only need those you are currently targeting in one of your projects.

For example: If you´re working on one .NETCore project, and you just did those 2 steps with Versions 2.1.4 - as time of writing you only need Microsoft .NET Core SDK 2.1.402. To clean up a little I uninstalled every .NET Core SDK/Runtimes/Packages and just took the latest from here.

Note: I followed this blogpost from Jeff Atwood to answer a question, which took me too long to resolve. I hope that helps...

EDIT: Good news for .NET Core 2.2: You just have to edit the .csproj as follows:

<PropertyGroup>
  <TargetFramework>netcoreapp2.2</TargetFramework>
  <RuntimeFrameworkVersion>2.2.0</RuntimeFrameworkVersion>
</PropertyGroup>

EDIT: The metapackages should not be updated manually anymore. This is the recommendation for updating AspNetCore. The version of the metapackage depends on the installed SDK.

这篇关于如何解决.net Core构建错误NETDSDK1061和警告MSB3277的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆