错误NU1202从NET 5.0升级到NET 6.0
我正在努力将项目从Net 5.0升级到Net 6.0,并且在VS 2022中构建良好,但我正在尝试通过命令行构建它:
dotnet restore
dotnet publish /p:Configuration=Release
/p:PublishProfile=FolderProfile
并获取以下错误:
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)
这是.csproj 项目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>
这是我的服务器上安装了net 6.0的屏幕截图: net 6.0 sdk
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
删除参数
或更改《目标帧》
内容。
Remove the parameter
Or change the 《TargetFramework》 in the
content.
在顺序
1中尝试这些。检查您没有一个全局。JSON指向错误的SDK:
2。重新安装DotNet,以确保肯定会拾取最新的SDK:
有时默认情况下会拾取错误的SDK。您没有说什么平台,我假设窗户。
尝试以下操作:
您可以使用 winget ,安装(或更新) .NET:
从管理员命令提示符
Try these in order
1. Check you don't have a global.json pointing to the wrong SDK:
2. Reinstall dotnet to make sure the latest SDK is definitely being picked up:
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:
Run from an admin command prompt
我之前遇到了同样的问题(但是从升级.NET 6到.NET 7),我在网上发现的和其他答案并没有解决该问题。最终,我注意到我还没有更新发布个人资料文件。在里面仍然留下来:
一旦我更新了,它又可以正常工作了
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:
Once i updated that, it was working correctly again