Reputation: 1
I am working on upgrading a project from NET 5.0 to NET 6.0 and it builds just fine in VS 2022 but I am trying to build it through command line using:
dotnet restore
dotnet publish /p:Configuration=Release
/p:PublishProfile=FolderProfile
and get the following errors:
error NU1202: Package Microsoft.AspNetCore.Components.Web 6.0.3 is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Package Microsoft.AspNetCore.Components.Web 6.0.3 supports: net6.0 (.NETCoreApp,Version=v6.0)
error NU1202: Package Microsoft.AspNetCore.Mvc.NewtonsoftJson 6.0.3 is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Package Microsoft.AspNetCore.Mvc.NewtonsoftJson 6.0.3 supports: net6.0 (.NETCoreApp,Version=v6.0)
error NU1201: Project X is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Project X supports: net6.0 (.NETCoreApp,Version=v6.0)
Here is the .csproj
file for Project X:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="Request\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
</Project>
And here is a screenshot showing NET 6.0 is installed on my server: NET 6.0 SDK
Upvotes: 0
Views: 5446
Reputation: 11
Remove the parameter
/p:PublishProfile=FolderProfile
Or change the 《TargetFramework》 in the
Properties\PublishProfiles\FolderProfile.pubxml
content.
Upvotes: 1
Reputation: 69
I had the same issue earlier (however from upgrading .net 6 to .net 7) and this and other answers i found online didn't fix the issue for me. Eventually i noticed that i hadn't also updated my publish profile file. Inside it was still staying:
<TargetFramework>net6.0</TargetFramework>
Once i updated that, it was working correctly again
Upvotes: 3
Reputation: 11097
{
"sdk": {
"version": "5.0.0"
}
}
Sometimes the wrong SDK is picked up by default. You didn't say what platform, I'm assuming windows.
Try this: You can use WinGet, to install (or update) .NET:
winget install Microsoft.dotnet
Upvotes: 0