82
votes

I have a dotnet core app that is targetting Microsoft.NETCore.App 1.1.2. I created a test project to test against that project but when building I noticed this warning: enter image description here

I open the NuGet Package Manager and see that warning is correct, the project being tested has a different version of Microsoft.NETCore.App: enter image description here enter image description here

My problem is that Visual Studio is not letting me update that version, so I'm confused on how to solve this issue: enter image description here Ideally I would just click the dropdown and select the right version but Visual Studio claims that it cannot do this because of "additional constraints in the project or packages.config". How am I supposed to update that package? What "additional constraints" is Visual Studio referring to?

8
Looks like the test project is blocking the downgrade. Did you try to right click on the solution and select manage nuget packages for the solution and move all the projects to the different version at the same time?Ken Tucker
I hadn't thought of that but I just tried it and I get that same "Blocked by project" error. Also the other project is blocked from moving away from 1.1.2. I also installed the latest update for VS but that didn't help.riqitang
I´ve collected all information I found in this question/answer: stackoverflow.com/questions/52518059/… because this problem seems to be really a question. The answers here are not complete for my scenarioJoshit
Had the same error when I was mistakenly targeting different versions of the .net core framework across different projects in my solution. Make sure the project properties for each target the same version.obaylis

8 Answers

51
votes

EDIT 2018: Only follow the instructions for updating the package if you really know what you are doing. In most cases, you never need to update this package - or other packages marked as "blocked by project" - manually. A framework-dependent app will use the latest runtime available and a self-contained application will perform an extra build using a newer version of this package automatically. (there are some edge cases where you need to upgrade this package in test projects. in this case, add <TargetLatestRuntimePatch>true</…> and see this Q&A for other options)

The implicit package references that the Microsoft.NET.Sdk infers can't be updated via NuGet.

If you migrated from project.json, the project with the 1.1.0 reference likely contains

<RuntimeFrameworkVersion>1.1.0</RuntimeFrameworkVersion>

in the csproj file or an item like this (if you may used the package manager previously to set the version):

<PackageReference Update="Microsoft.NETCore.App" Version="1.1.0" />

Delete entries like the above and all packages will reference 1.1.2 (or whatever the installed SDK considers to be the latest) automatically. Alernatively, set RuntimeFrameworkVersion in all projects.

49
votes

I had similar problem trying to install Entityframework.Core package in a .NET Core 2 Web app. To solve the issue, I've forced installation through Package Manager Console:

Install-Package Microsoft.NETCore.App -Version 2.0.5

(2.0.5 was the most recent version at the time)

I hope it's useful. Peace.

19
votes

For me adding

<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>

did the trick

<PropertyGroup>
  <TargetFramework>netcoreapp2.1</TargetFramework>
  <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>
7
votes

Short Answer

Add an explicit version to the Microsoft.AspNetCore.App package reference in your .csproj file.

Long Answer

I had a brand new netcoreapp2.1 project. The following was in the .csproj file. Note there was no version associated with the Microsoft.AspNetCore.App package reference.

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

I added an explicit reference to the Microsoft.Extensions.Logging.Abstractions package to resolve a dependency mismatch (build error). Micorsoft.AspNetCore.App wanted version 2.1.0 of this dependency, but another package wanted version 2.1.1. My .csproj file now looked like this.

<ItemGroup>
  ...
  <PackageReference Include="Microsoft.AspNetCore.App" />
  <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.1.1" />
  ...
</ItemGroup>

This reduced the build error to a warning about Micorsoft.AspNetCore.App requiring the 2.1.0 version of the Microsoft.Extensions.Logging.Abstractions package but version 2.1.1, of course, was resolved.

Trying to update Micorsoft.AspNetCore.App to version 2.1.1 to fix the warning was blocked by Package Manager as mentioned by the OP.

I updated my Micorsoft.AspNetCore.App package reference to explicitly use version 2.1.1 like this.

<ItemGroup>
  ...
  <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1" />
  <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.1.1" />
  ...
</ItemGroup>

This fixed the build warning and unblocked all the versions of Microsoft.AspNetCore.App in Package Manager. I was even able to remove the explicit reference to Microsoft.Extensions.Logging.Abstractions without reintroducing the original error. The final .csproj looked like this with no issues.

<ItemGroup>
  ...
  <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1" />
  ...
</ItemGroup>
3
votes

I had same problem and I think, the problem is about the package.

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

The problem was resolved after I specified version exactly.

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

As I know, that error is occured when the version number

2
votes

Another possible solution. In the csproj file, update the target framework to the version you wish to upgrade to. After making the change, as per below snippets, the packages can be upgraded via the solution NuGet package manager.

Before:

<PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

After:

<PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
0
votes

I solved it by simply: Right clicking on Project (or ALT+ Enter) -> Properties -> Application -> Target Framework (Choose .NET Core framework (in this case 1.1))

0
votes

The best recommendation is to recreate your projects again after upgrading the SDK and the run time and then drop your old code and configuration inside the new projects. Other than that, you will be spending too much time in useless tweaks and unknown configurations.