23

I am trying to convert a .NET Framework WPF app to .NET 5

I ran https://github.com/dotnet/try-convert, and removed some incompatible DLL refs.

Now, when I try to compile, I am presented with

NETSDK1135  SupportedOSPlatformVersion 10.0.19041.0 cannot be higher than TargetPlatformVersion 7.0

enter image description here

Any ideas as to what to look for? The project in question is a combination of .NET 5 and .NET Standard 2.1

3 Answers 3

19

I had the same error a few hours ago. I found this article useful: https://nicksnettravels.builttoroam.com/net-5-tfms/ As I understand the TargetFrameWork in the project file must include the same Windows version as the SDK Contract. My project file looks like this now:

  <PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
<UseWPF>true</UseWPF>
...
  <ItemGroup>
    <PackageReference Include="Microsoft.Windows.CsWinRT" Version="1.1.0" />
    <PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.19041.1" />
  </ItemGroup>

...

Hope it is useful for you.

19

This issue appeared on my end when adding Microsoft.Windows.SDK.Contracts to read the version applied during packaging using MSIX package.

I tried with @RolandJS solution, but still tons of errors.

Found: https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-enhance

It mentions that since .NET 5 (or a later release) and target Windows 10, version 1809 or a later, the Microsoft.Windows.SDK.Contracts is not needed anymore. Instead you should use the TargetFrameworkMoniker (TFM).

As mentioned by RolandJS already: In the project file change

<TargetFramework>net5.0-windows</TargetFramework>

to e.g.

<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>

Uninstall Microsoft.Windows.SDK.Contracts

3
  • this was what i needed! thank you
    – aherrick
    Commented Feb 5, 2022 at 13:35
  • I wish I could upvote this 15 times. This should be the answer!!
    – tmighty
    Commented Feb 18, 2022 at 0:08
  • work for me! (Contrary to accepted anwser below) Commented Sep 9 at 15:00
0

In my scenario I had by mistake 2 TargetFrameworks with windows keyword defined in my .csproj:

    <TargetFrameworks>net8.0-android;net8.0-ios;net8.0-windows</TargetFrameworks>
    <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.18362.0</TargetFrameworks>

So had to remove the net8.0-windows from the first line

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.