Unity includes Windows Runtime support for IL2CPP on Windows Store and Xbox One platforms. Use Windows Runtime support to call into both native system Windows Runtime APIs as well as custom .winmd files directly from managed code (scripts and DLLs).
To automatically enable Windows Runtime support in IL2CPP, go to PlayerSettings (Edit > Project Settings > Player), navigate to the Configuration section, and set the Api Compatibility Level to .NET 4.6.
Unity automatically references Windows Runtime APIs (such as Windows.winmd on Windows Store) when it has Windows Runtime support enabled. To use custom .winmd files, import them (together with any accompanying DLLs) into your Unity project folder. Then use the Plugin Inspector to configure the files for your target platform.
In your Unity project’s scripts you can use the ENABLE_WINMD_SUPPORT
#define directive to check that your project has Windows Runtime support enabled. Use this before a call to .winmd Windows APIs or custom .winmd scripts to ensure they can run and to ensure any scripts not relevant to Windows ignore them. See the examples below.
Examples
C#
void Start() {
#if ENABLE_WINMD_SUPPORT
Debug.Log("Windows Runtime Support enabled");
// Put calls to your custom .winmd API here
#endif
}
JS
function Awake() {
#if ENABLE_WINMD_SUPPORT
Debug.Log("Windows Runtime Support enabled");
// Put calls to your custom .winmd API here
#endif
}
In addition to being defined when Windows Runtime support is enabled in IL2CPP, it is also defined in .NET when you set Compilation Overrides to Use Net Core.