简体   繁体   中英

How to target WinPhone and WinRT in the same project?

I have created a Visual Studio 2012 C++/CX project that targets both WinPhone 8 and WinRT. The solution can be downloaded here (Hybrid.zip) if anyone is interested.

Unfortunately, it doesn't work as expected with the solution platforms. Two platforms are working properly:

  • If I select solution platform ARM , a native ARM WinPhone binary is built.

  • If I select solution platform x64 , a native 64-bit Windows binary is built.

However I have trouble with Win32 . The Windows Phone SDK understands Win32 as “WinPhone x86 binary for the simulator” whereas the Windows SDK understands Win32 as “Windows x86 native binary”. The same project platform is used for two very different things!

I have tried creating a solution platform WinPhoneEmu . However, I have no idea how to create a project platform that will let me have two different platform configuration choices Win32 and WinPhoneEmu that behave as I expect. How could I do that?

I'm pretty sure this is explicitly not supported . The primary reason being that the XAML syntax between WinRT and Phone is similar, but not exactly compatible (phone is Silverlight-ish, WinRT is some weird new thing).

The best way to target both is to have a total of 3 projects:

  1. A portable class library targeting Phone and WinRT where all your logic goes
  2. A UI layer for WinRT that links to the PCL
  3. A UI layer for Phone that links to the PCL

If I've understood you correctly, in this situation you need to select both platform (x86, x64, ARM) and target (Device, Emulator) manually. You can do it easily by adding platform selector in Visual Studio toolbar. Tools -> Customize -> Commands -> Toolbar -> Standard, then add 'Solution Platforms" command. This is a combo box with x86, x64, ARM, Any CPU, etc. Then you'll be able to select, say, x86 + Emulator WXGA for WP8 emulator, or x86 + Device for W8 device:

看我的截图

... and here how it will look in VS after that:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM