Imagine a scenario where you have a complex framework of WinRT code that you would like to access from both C++ Metro Apps and C# Desktop Apps.
Is there any way to incl
UPDATE: This only works with Windows 8. Microsoft disabled this in Windows 8.1.
Yes, there is. The block when attempting to add them via the reference manager appears to be implemented inside Visual Studio itself. Once added, Visual Studio will treat the referenced file as it would any other WinMD file.
NOTE: THIS WORKAROUND IS NOT SUPPORTED BY MICROSOFT!
To add your custom WinMD file to any Non-Metro application you must first ensure that you are targeting .NET 4.5. This will not work with any prior version of the .NET Framework.
Once you are targeting .NET 4.5 unload the project file and open it for editing. Then, add the following code after the last <PropertyGroup>
in the project file:
<PropertyGroup>
<TargetPlatformVersion>8.0</TargetPlatformVersion>
</PropertyGroup>
Next, find the <ItemGroup>
that contains your references and add the following:
<Reference Include="{Namespace}">
<HintPath>{Path to WinMD file}</HintPath>
</Reference>
While I cannot guarantee that no problems will arise from doing this, and given that Microsoft has been VERY clear about the fact that regardless of which Framework Profile you are using the CLR is loading the same Assemblies, I strongly suspect that this will not cause any harm.
A note on Class Libraries. If you include your WinMD into a non-Metro Class Library and then reference that library in a non-Metro application; you will be unable to access any of the custom WinRT types that your Class Library exposes without either referencing the WinMD file in your application or providing wrapper types.