Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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).

enter image description here

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.).

like image 934
Joshit Avatar asked Sep 26 '18 12:09

Joshit


People also ask

Why am I unable to resolve the SDK version in netsdk1141?

NETSDK1141: Unable to resolve the .NET SDK version as specified in the global.json located at C:\path\global.json. The SDK version in the global.json file is incorrectly specified. The SDK version specified in the global.json file was not installed.

How do I find the conflicting version of MSBuild in error?

When this error occurs with MSBuild 16.x or later, the specific versions that are in conflict are written to the log file. If you're using an earlier version of MSBuild, this isn't in the log file, but you can usually follow the dependency chain to find the conflicting reference.

What is this msb3277 error?

warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed. But really the relevant portion is 1#:

Do I need the net core SDK for my project?

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.


1 Answers

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.

like image 134
Joshit Avatar answered Oct 25 '22 22:10

Joshit