83

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?

5
  • 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
    May 17, 2017 at 16:19
  • 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
    May 17, 2017 at 17:10
  • Possible duplicate of Why I can't consolidate projects sdk versions in Visual Studio?
    – astef
    Jun 10, 2018 at 23:38
  • 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 scenario
    – Joshit
    Sep 26, 2018 at 12:53
  • 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
    Mar 10, 2019 at 10:05

8 Answers 8

51

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.

1
  • 2
    You were right: I opened the .csproj file and removed the <RuntimeFrameworkVersion>1.1.0</RuntimeFrameworkVersion> line. VS still won't let me manually change the version but at least it's the right version now (it updated to 1.1.2 like you said it would)
    – riqitang
    May 17, 2017 at 18:11
49

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.

5
  • 7
    This worked for me upgrading to 2.1.1 -> Great answer and missing from all articles I could find.
    – Paul
    Jun 29, 2018 at 4:39
  • This finally worked for me as well. After calling this in the pmc of VS2017 for each project I upgraded to v2.1.3 from v2.1.0
    – Paul Meems
    Aug 24, 2018 at 10:03
  • 1
    Install-Package Microsoft.NETCore.App
    – Dorathoto
    Sep 19, 2018 at 13:16
  • 5
    Why does it 'blocked by project' at all though? Is this some kind of bug or is there a good reason? if there's a good reason perhaps doing the above isn't a good idea? Or does it fix said problem?
    – niico
    Oct 17, 2018 at 0:19
  • Thanks for this hint. So "Blocked by project" turned out as "Blocked by VS NuGet GUI".
    – Grimm
    Jan 28, 2020 at 9:25
19

For me adding

<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>

did the trick

<PropertyGroup>
  <TargetFramework>netcoreapp2.1</TargetFramework>
  <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>
5
  • So this would target the latest version of the framework on the current machine. If local computer is patched and host server is then wouldn't this run into issues?
    – jonmeyer
    Sep 17, 2018 at 16:16
  • I actually don't know because we are doing self-contained deployments. But as a wild guess I would imagine since it says "latest" and no specific version that it would just not use any if not present. @jonmeyer
    – gsharp
    Sep 17, 2018 at 17:31
  • I had different versions installed in my solution. I edited all of them to add this line. Brought them to the same version and then deleted the line again. But I still get the message blocked by project when I manage nuget packages for solution.
    – sam
    Sep 20, 2018 at 0:13
  • @sam did you try the others solutions too? it seems that the two answers with 30+ votes also work for some people.
    – gsharp
    Sep 20, 2018 at 4:37
  • Yeah. I did. What i'm trying to do is use the manage nuget packages for solution option in the UI and install/ uninstall using mouse clicks. Not having to edit the csproj files manually. And I haven't been able to do that using the UI. Your way and the other options work, but the UI doesn't work.
    – sam
    Sep 21, 2018 at 16:11
7

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

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

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

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.