在非地铁应用程序中使用自定义的Windows运行时组件 [英] Using Custom Windows Runtime Components in Non-Metro Applications

查看:212
本文介绍了在非地铁应用程序中使用自定义的Windows运行时组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下这样一个场景,你有WinRT的code一个复杂的框架,你想从两个C ++地铁应用程序和C#桌面应用程序来访问。

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.

有没有什么办法,包括WinMD在非Metro应用?

Is there any way to include WinMD in a non-Metro application?

推荐答案

更新:在Windows 8.1禁用这与Windows 8微软这只适用

UPDATE: This only works with Windows 8. Microsoft disabled this in Windows 8.1.

是的,有。试图通过参考经理加入他们时,该块出现在Visual Studio的本身来实现。添加后,Visual Studio将处理引用的文件,因为这将任何其他WinMD文件。

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.

注意:此变通办法不支持通过Microsoft

NOTE: THIS WORKAROUND IS NOT SUPPORTED BY MICROSOFT!

要添加自定义WinMD文件到任何非Metro应用必须首先确保您的目标.NET 4.5。这不会与.NET Framework的任何早期版本的工作。

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.

在你的目标.NET 4.5卸载项目文件并打开它进行编辑。然后,后添加以下code中的最后一个<的PropertyGroup> 在项目文件:

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>

接下来,找到&LT; ItemGroup&GT; 包含您参考,并添加以下内容:

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

<Reference Include="{Namespace}">
  <HintPath>{Path to WinMD file}</HintPath>
</Reference>

虽然我不能保证没有问题,将产生于这样做,并鉴于微软一直非常清楚,无论哪个框架简介您正在使用的加载同一个程序集的CLR的事实,我强烈怀疑,这将不会造成任何伤害。

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.

在类库的说明。如果您包括您WinMD到非地铁类库,然后引用该库在非Metro应用;您将无法访问任何自定义WinRT的类型,你的类库没有公开任何引用WinMD文件中的应用程序或提供包装的类型。

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.

这篇关于在非地铁应用程序中使用自定义的Windows运行时组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆