Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2017 cannot update Microsoft.NETCore.App package ("Blocked by project")

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?

like image 326
riqitang Avatar asked May 17 '17 13:05

riqitang


People also ask

What is NET Core app?

ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-enabled, Internet-connected apps. With ASP.NET Core, you can: Build web apps and services, Internet of Things (IoT) apps, and mobile backends. Use your favorite development tools on Windows, macOS, and Linux.

How do I view .NET Core in Visual Studio?

NET Core is installed on Windows is: Press Windows + R. Type cmd. On the command prompt, type dotnet --version.

Does Visual Studio 2019 include .NET Core SDK?

As you have seen, Visual Studio 2019 installer includes . NET Core 2.1 but not . NET Core 3.


4 Answers

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.

like image 163
Martin Ullrich Avatar answered Oct 19 '22 16:10

Martin Ullrich


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.

like image 20
Marlon Dias Avatar answered Oct 19 '22 15:10

Marlon Dias


For me adding

<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>

did the trick

<PropertyGroup>
  <TargetFramework>netcoreapp2.1</TargetFramework>
  <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>
like image 19
gsharp Avatar answered Oct 19 '22 15:10

gsharp


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>
like image 7
bugged87 Avatar answered Oct 19 '22 16:10

bugged87