Using Custom Windows Runtime Components in Non-Metro Applications

前端 未结 1 1776
青春惊慌失措
青春惊慌失措 2021-02-10 09:42

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

1条回答
  •  广开言路
    2021-02-10 09:59

    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 in the project file:

      
        8.0
      
    

    Next, find the that contains your references and add the following:

    
      {Path to WinMD file}
    
    

    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.

    0 讨论(0)
提交回复
热议问题