NU1202:软件包与 net50 不兼容-windows
NU1202: Package is not compatible with net50-windows
我有一个引用用户控件库的 .NET 5 WPF 应用程序 (x64)。
当我直接引用库时,一切正常。
但是当我创建一个 Nuget 包,然后在我的构建服务器上构建引用该 Nuget 包的应用程序时,我得到:
NU1202: Package MyControls is not compatible with net50-windows (.NETFramework,Version=v5.0,Profile=windows) / win-x64.
Package MyControls supports:
- net50-windows7.0 (.NETFramework,Version=v5.0,Profile=windows7.0)
- netcoreapp3.1 (.NETCoreApp,Version=v3.1)
MyControls .csproj 文件包含以下内容:
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0-windows</TargetFrameworks>
<UseWPF>true</UseWPF>
<RuntimeIdentifiers>win;win-x64</RuntimeIdentifiers>
</PropertyGroup>
应用 .csproj 文件包含以下内容:
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
</PropertyGroup>
我不明白为什么它会输出 windows 7 的包。
我发现这个 link 描述了它:
https://github.com/dotnet/sdk/issues/14553
那里的评论之一似乎符合我的情况:
I had the same phenomenon and when I tried to install these packages
in a .NET 5 app, it told me that "net5.0" and "net.5.0-windows7.0"
aren't compatible. All my projects where "net5.0-windows" actually,
though.
如果我手动将 net5.0-windows7.0 文件夹复制到 .nuget/packages 下的新文件夹 net5.0-windows,Nuget 错误就会消失。
但是我得到了这个编译错误:
errorCS0103: The name 'Windows' does not exist in the current context
我应该更改什么以使 Nuget 恢复正常工作?
我已经用这两个 csproj 文件测试了你的问题,没有遇到相同的行为。
所以请尝试以下步骤:
首先在您的应用项目上卸载 MyControls
nuget 包。
然后,clean nuget caches或删除C:\Users\xxx\.nuget\packages
下的所有文件
删除应用项目的bin
和obj
文件夹。
重新安装 MyControls
nuget 包再次测试。
我将目标框架从 windows 更改为 windows 10,如下所示:
MyControls(Nuget 包)csproj:
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0-windows10.0.19041.0</TargetFrameworks>
<UseWPF>true</UseWPF>
</PropertyGroup>
应用程序 csproj:
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
<UseWPF>true</UseWPF>
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
之后恢复错误消失了。
将 NuGet 版本增加到 5.X 对我有用。它应该在 restore
之前添加
我将 2017 年使用的 visual studio 版本更改为 2022 年,这为我解决了这个问题,并且可以使用最新版本构建解决方案。
我有一个引用用户控件库的 .NET 5 WPF 应用程序 (x64)。 当我直接引用库时,一切正常。
但是当我创建一个 Nuget 包,然后在我的构建服务器上构建引用该 Nuget 包的应用程序时,我得到:
NU1202: Package MyControls is not compatible with net50-windows (.NETFramework,Version=v5.0,Profile=windows) / win-x64.
Package MyControls supports:
- net50-windows7.0 (.NETFramework,Version=v5.0,Profile=windows7.0)
- netcoreapp3.1 (.NETCoreApp,Version=v3.1)
MyControls .csproj 文件包含以下内容:
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0-windows</TargetFrameworks>
<UseWPF>true</UseWPF>
<RuntimeIdentifiers>win;win-x64</RuntimeIdentifiers>
</PropertyGroup>
应用 .csproj 文件包含以下内容:
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
</PropertyGroup>
我不明白为什么它会输出 windows 7 的包。 我发现这个 link 描述了它: https://github.com/dotnet/sdk/issues/14553 那里的评论之一似乎符合我的情况:
I had the same phenomenon and when I tried to install these packages in a .NET 5 app, it told me that "net5.0" and "net.5.0-windows7.0" aren't compatible. All my projects where "net5.0-windows" actually, though.
如果我手动将 net5.0-windows7.0 文件夹复制到 .nuget/packages 下的新文件夹 net5.0-windows,Nuget 错误就会消失。
但是我得到了这个编译错误:
errorCS0103: The name 'Windows' does not exist in the current context
我应该更改什么以使 Nuget 恢复正常工作?
我已经用这两个 csproj 文件测试了你的问题,没有遇到相同的行为。
所以请尝试以下步骤:
首先在您的应用项目上卸载
MyControls
nuget 包。然后,clean nuget caches或删除
下的所有文件C:\Users\xxx\.nuget\packages
删除应用项目的
bin
和obj
文件夹。重新安装
MyControls
nuget 包再次测试。
我将目标框架从 windows 更改为 windows 10,如下所示:
MyControls(Nuget 包)csproj:
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0-windows10.0.19041.0</TargetFrameworks>
<UseWPF>true</UseWPF>
</PropertyGroup>
应用程序 csproj:
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
<UseWPF>true</UseWPF>
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
之后恢复错误消失了。
将 NuGet 版本增加到 5.X 对我有用。它应该在 restore
之前添加我将 2017 年使用的 visual studio 版本更改为 2022 年,这为我解决了这个问题,并且可以使用最新版本构建解决方案。