XapDeployCmd.exe is the commandline tool for everything related to XAP deployments. More information on the tool can be found on MSDN
Choose the emulator of your choose from the list and remember its index.
Time to start building the script. In your Windows Phone 8 project, go to the project properties to the Build Events tab. In the Post-build event command line box enter this script.
The first line of the script navigates the command line to the folder where the XapDeployCmd lives (this is the default install path, the tool comes with the WP8 SDK). The second line launches the tool and passes the necessary parameters. the installaunch parameter states that the app should install (or update) the app and launch it when finished. After the installaunch parameter we need to state the path to the xap file, by default (when using the debug configuration in VS2012) it’s in the bin/debug folder and is called something like MyWPApp_debug_anycpu.xap. To make the script easy to transfer over I’ve used variables instead of hardcoding the path and the xap name. Here’s a quick rundown.
|$(TargetDir)||the full path to the outputdirectory (for example: c:\users\nico\documents\Projects\MyWPApp\bin\debug\) |
Keep in mind that the last “\” is always included when using this variable
|$(ProjectName)||The name of the project (didn’t see that one coming, did you? ) (for example: MyWPApp)|
|$(ConfigurationName)||The used configuration, for example ”release” or “debug”|
|$(PlatformName)||The selected CPU architecture, for example “AllCpu”, “ARM”, “x86”|
powers variables combined we get the full path to the xap file. The last parameter specifies the to use emulator by passing in the index that we determined at the beginning of this post.
And that’s it. Rebuild your solution and watch the emulator start app, deploy and launch your app. Now every time that you change the code of the app and hit the debug button it will build and deploy to both emulators. One of the emulators should have those debug numbers on the side, making it easy to recognize which one has the debugger attached.
Using a very simple post-build script and the in the WP8 included XapDeployCmd tool it’s very easy to deploy an application to two devices simultaneously. This isn’t needed very often but when building something that connects users to each other (like a chat application or a multiplayer game) it can save you quite some hassle. Just make sure that your script uses another emulator version than Visual Studio 2012.