错误NU1202从NET 5.0升级到NET 6.0

发布于 2025-01-22 20:04:02 字数 1361 浏览 3 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

洒一地阳光 2025-01-29 20:04:04

删除参数

/p:PublishProfile=FolderProfile 

或更改《目标帧》

properties \ prublishProfiles \ folderProfile.pubxml

内容。

Remove the parameter

/p:PublishProfile=FolderProfile 

Or change the 《TargetFramework》 in the

Properties\PublishProfiles\FolderProfile.pubxml

content.

月光色 2025-01-29 20:04:04

在顺序

1中尝试这些。检查您没有一个全局。JSON指向错误的SDK:

{
  "sdk": {
    "version": "5.0.0"
  }
}

2。重新安装DotNet,以确保肯定会拾取最新的SDK:

有时默认情况下会拾取错误的SDK。您没有说什么平台,我假设窗户。

尝试以下操作:
您可以使用 winget ,安装(或更新) .NET:

从管理员命令提示符

winget install Microsoft.dotnet

Try these in order

1. Check you don't have a global.json pointing to the wrong SDK:

{
  "sdk": {
    "version": "5.0.0"
  }
}

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

winget install Microsoft.dotnet
赏烟花じ飞满天 2025-01-29 20:04:03

我之前遇到了同样的问题(但是从升级.NET 6到.NET 7),我在网上发现的和其他答案并没有解决该问题。最终,我注意到我还没有更新发布个人资料文件。在里面仍然留下来:

<TargetFramework>net6.0</TargetFramework>

一旦我更新了,它又可以正常工作了

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文