I have a .NET 5 WPF application (x64) that references a user control library. When I reference the library directly, everything works.
But when I create a Nuget package and then build the app referencing the Nuget package on my build server I get:
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)
The MyControls .csproj file contains this:
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0-windows</TargetFrameworks>
<UseWPF>true</UseWPF>
<RuntimeIdentifiers>win;win-x64</RuntimeIdentifiers>
</PropertyGroup>
The app .csproj file contains this:
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
</PropertyGroup>
I don't understand why it outputs a package for windows 7. I found this link that describes it: https://github.com/dotnet/sdk/issues/14553 One of the comments in there seems to match my case:
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.
If I manually copy the net5.0-windows7.0 folder to a new folder net5.0-windows under .nuget/packages, the Nuget error goes away.
But instead I get this compile error:
errorCS0103: The name 'Windows' does not exist in the current context
What should I change to make the Nuget restore work?