This version of Microsoft.AspNetCore.All is only c

2020-05-24 19:48发布

问题:

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]

回答1:

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



回答2:

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.



回答3:

  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.


回答4:

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



回答5:

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



回答6:

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.



回答7:

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.



回答8:

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>


回答9:

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.