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

查看:37
本文介绍了如何解决 .net 核心构建错误 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 -版本 2.1.4Install-Package Microsoft.AspNetCore.App -Version 2.1.4).

执行该命令后,我遇到了构建错误(NETSDK1061:该项目已使用 Microsoft.NETCore.App 版本 2.1.4 恢复,但在当前设置下,将使用版本 2.1.0.要解决对于此问题,请确保将相同的设置用于还原和后续操作,例如构建或发布.).

解决方案

我试图在这个问题上找到任何帮助,找到了一些 GitHub 问题(例如 这个) 看起来非常相似,但实际上不同.我找到了一个描述性文档,但这并没有真正帮助我.

我发现了一个 来自 Rick Strahl 的非常有用的博客文章,解释了哪些包可用以及每个包的用途是什么.这是一个很好的开始.

这是我的解决方案:

第 1 步:在包管理器控制台中执行 Install-Package Microsoft.AspNetCore.App -Version [VersionOfYourChoice] 和/或执行 Install-Package Microsoft.NETCore.App -Version [VersionOfYourChoice].

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

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

另外一点:如果您使用 Win10,请帮自己一个忙并检查已安装的 .NET Core SDK/运行时等.卸载您不需要的所有 SDK/运行时(再次:检查 Rick 的博客文章).您只需要当前在您的项目之一中定位的对象.

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

注意:我关注了这篇来自 Jeff 的博文Atwood 来回答一个我花了太长时间才解决的问题.我希望这会有所帮助.

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

<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 were actually different. I´ve found a descriptive doc, but that didn´t really helped me.

I found a pretty helpful blog post 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 Rick's blog post for that). You only need those you are currently targeting in one of your projects.

For example: If you´re working on one .NET Core 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 blog post 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 核心构建错误 NETDSDK1061 和警告 MSB3277的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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