How to resolve .net core build error NETDSDK1061 and warning MSB3277

旧巷老猫 提交于 2019-11-28 01:26:15

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.

After adding this line to the .csproj file I was still seeing this issue.

<RuntimeFrameworkVersion>2.1.5</RuntimeFrameworkVersion>

Adding the Version attribute to the Microsoft.AspNetCore.App package reference resolved the issue for me. I changed this:

<PackageReference Include="Microsoft.AspNetCore.App" />

to this:

<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.5" />

Step 1 in @Joshit's answer probably does this automatically, but I already had the latest version of Microsoft.AspNetCore.App.

Ug. This issue was very sticky for me. I did the steps in @Joshit's answer and the error persisted. Then I did:

  • Build > Clean Solution
  • Build > Build Solution

Now it is working.

It helps to know your SDK version, which can be found here: C:\Program Files\dotnet\sdk

You can get this problem doing a publish as well. It can be helpful to add this line to the publish_profile.pubxml file:

<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.1.0</RuntimeFrameworkVersion>

Replace 2.1.0 with 2.1.4 or whatever you are using.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!