This version of Microsoft.AspNetCore.All is only compatible with the netcoreapp2.1 target framework

C#Razor Pages.Net Core-2.1

C# Problem Overview


When I try to publish my application to the web server after upgrading to .NET Core 2.1 from 2.0, I get this message: "This version of Microsoft.AspNetCore.All is only compatible with the netcoreapp2.1 target framework. Please target netcoreapp2.1 or choose a version of Microsoft.AspNetCore.All compatible with netcoreapp2.0."

It runs fine on my development machine.

Here is my project file:

<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0" />
    <PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.4" />
</ItemGroup>
</Project>

I have seen this, but it does not seem to be the problem. I have also experimented with the prerelease 2.1 version of CodeGeneration.Tools, but I was not able to install it.

EDIT: I did install dotnet 2.1 on the server.

Here's what I see on the server:

D:\>dotnet --info
Host (useful for support):
  Version: 2.1.0
  Commit:  caa7b7e2ba

.NET Core SDKs installed:
  No SDKs were found.

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.0 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.0 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.5 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.6 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.0 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]

C# Solutions


Solution 1 - C#

I had the same problem, but then I had not updated the publish profile file(.pubxml) for the right targetenvironment

< TargetFramework>netcoreapp2.1< /TargetFramework>

And regarding to earlier answer the row

< DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.1" />

Show be removed in 2.1 version beacuse of obsolete and are included nowaday

Solution 2 - C#

To follow on from joakimja's post, you can also update the .pubxml file via the VS2017 IDE. Right click on your project and select "publish" and then click "configure" on the "trouble shooting info" row, then go to the "settings" tab, here you can set the "Target Framework" - in fact this should have automatically updated to "netcoreapp2.1" just by opening the dialog. Click "Save" and this will update the target framework in the pubxml file. Then try publishing again.

Solution 3 - C#

  1. You possibly need to do clean on the project first.
  2. Right click on the Project File in Visual Studio.
  3. Click the properties select the Application -> Target Framework drop down and choose the version of .Net Core Framework you are wanting to use.
  4. Rebuild your solution.

Solution 4 - C#

What helped me is just deleting the .pubxml file(s) under the Properties > PublishProfiles folder and then recreating the publish profile again.

Solution 5 - C#

enter image description hereI was stuck with this issue for about 3 hours. Eventually, this error came when I added a Nuget package Microsoft.VisualStudio.Web.CodeGeneration.Design. This is what I did to solve this issue:

  1. Deleted bin folder of my .net core project

  2. Explicitly added the dotnet version to TargetFramework and PackageReference to 2.1.0. You can try adding what is best for your project and dotnet version.

  3. I restored the project with dotnet restore and then build with dotnet build

  4. At the end, my problem was solved and I no longer receive this error.

Solution 6 - C#

I ran into the same problem (error) when trying to deploy my upgraded solution to AWS Lambda using:

> dotnet lambda deploy-serverless

It turned out that I'd forgotten to update my aws-lambda-tools-defaults.json file.

"framework"     : "netcoreapp2.1",

Adding for others in the same situation.

Solution 7 - C#

Im guessing you pulled all the 2.1.x upgrades but initially started your project in 2.0.x. I just hand edit the cspoj file by downgrading back down and adding:

<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
    <TargetFramework>netcoreapp2</TargetFramework>

</PropertyGroup>


<ItemGroup>             
<PackageReference Include=
"Microsoft.AspNetCore.All" Version="2.0.3" />
<PackageReference Include=
"Microsoft.AspNetCore.Cors" Version="2.0.3" />                  
<PackageReference Include=
"Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.3" />                            
<PackageReference Include=
"Microsoft.EntityFrameworkCore.Tools" Version="2.0.3" PrivateAssets="All" />       
<PackageReference Include=
"Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.4" PrivateAssets="All" />
</ItemGroup>  

     
<ItemGroup>                      
<DotNetCliToolReferenceInclude=
    "Microsoft.EntityFrameworkCore.Tools.DotNet"Version="2.0.3" />   
<DotNetCliToolReferenceInclude=
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.4" /> 
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.3" />       
</ItemGroup>

So I think you are missing the <DotNetCliToolReferenceInclude=> item group.

Solution 8 - C#

I tried most of the suggestions I could find but what ended up fixing the issue was deleting the Microsoft.AspNetCore.All package from here:

%userprofile%.nuget\packages\microsoft.aspnetcore.all\2.1.5\build\netcoreapp2.1\

The next build restored the correct version.

Solution 9 - C#

Sorry for late reply,

I got this error now and found the solution.

We need to change TargetFramework version in PublishProfiles to netcoreapp2.2

<_SavePWD>True</_SavePWD>
<_DestinationType>AzureWebSite</_DestinationType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<SelfContained>false</SelfContained>
<_IsPortable>true</_IsPortable>

Solution 10 - C#

I deleted my obj folder inside project which had json files pointing to 2.2 version from previous build.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJim SView Question on Stackoverflow
Solution 1 - C#joakimjaView Answer on Stackoverflow
Solution 2 - C#MattView Answer on Stackoverflow
Solution 3 - C#Allan F. GagnonView Answer on Stackoverflow
Solution 4 - C#Robert KochView Answer on Stackoverflow
Solution 5 - C#muhammad tayyabView Answer on Stackoverflow
Solution 6 - C#TommyNView Answer on Stackoverflow
Solution 7 - C#Mohamoud MohamedView Answer on Stackoverflow
Solution 8 - C#ZaifworksView Answer on Stackoverflow
Solution 9 - C#Ranga VadhineniView Answer on Stackoverflow
Solution 10 - C#PraveenView Answer on Stackoverflow