Skip to content

Instantly share code, notes, and snippets.

@WamWooWam
Last active December 7, 2022 10:51
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WamWooWam/e72e5137606f7c59ed657db6587cd5e8 to your computer and use it in GitHub Desktop.
Save WamWooWam/e72e5137606f7c59ed657db6587cd5e8 to your computer and use it in GitHub Desktop.
How to use .NET Standard 2.0 under UWP <= 10.0.15063

Enabling .NET Standard support on UWP apps targeting 15063 or below is relatively simple.

Step 1

Set your project's TargetPlatformMinVersion to anything above 15063, for this I've always used 16299 but other SDKs should work the same way

step-1

Step 2

Open your .csproj file in a text editor (right click, "Unload project", right click again, "Edit project file"), and add the following 2 lines to the first property group.

<AppxOSMinVersionReplaceManifestVersion>false</AppxOSMinVersionReplaceManifestVersion>
<AppxOSMaxVersionTestedReplaceManifestVersion>false</AppxOSMaxVersionTestedReplaceManifestVersion>

These two (seemingly undocumented) properties allow you to set the TargetPlatformVersion and TargetPlatformMinVersion manually in your .appxmanifest file without them being clobbered by the build process, which we'll do next.

Step 3

Open your Package.appxmanifest file in a text editor (right click, "View Code"), and modify the TargetDeviceFamily element to specify a MinVersion and MaxVersionTested like so

<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.15035.0" MaxVersionTested="10.0.17763.0" />

Now, rebuild your project and try deploying it to an older version of Windows 10, all of your new fancy .NET runtime features and packages should* work perfectly, and in my experience, it passes WACK just fine meaning you can submit to the store like this!

Pros

  • Access to the tens of thousands of new APIs added in .NET Standard 2.0
  • Access to the thousands of libraries that require > .NET Standard 1.4
    • This includes referencing certain .NET Framework only libraries, just like regular .NET Core
  • The new .NET Native compiler with much better support for unsafe and optimised code
  • The ability to target ARM64 as well as 32-bit ARM without multiple project files/configurations

Cons

Microsoft, contrary to popular belief, don't just lock these things out for no reason, there are some drawbacks you should be aware of:

  • Debug/ARM builds do not work on Windows Phone unless they are compiled with the .NET Native compiler.
  • This does not allow you to use new Windows Runtime or XAML features on older versions of Windows.
    • Visual Studio Intelisense will also not inform you if specific APIs aren't supported on your real minimum Windows version.
  • Certain packages (namely the Windows Community Toolkit) that aren't tested or explicitly don't support older versions of Windows may include incompatible XAML.
  • I haven't tested all of the thousands of APIs added in .NET Standard 2.0, it's definitely possible some of them don't work prior to 16299, however I am yet to run into any that don't.

If you try this, and run into issues not listed here, please let me know so I can add them!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment