What the Hyper-V? WP8 SDK Emulator and Hyper-V Insights
As I noted in an earlier post [ http://blogs.msdn.com/b/devfish/archive/2012/11/06/are-you-slat-compatible-wp8-sdk-tip-01.aspx ], the Windows Phone 8 emulator requires Hyper-V if you wish to work against the emulator. So what’s going on under the hood? Let’s take a peek at some of the Hyper-V points going on with Windows 8 and Hyper-V.
The Windows Phone 8 SDK ships with four different emulator images – 512meg memory constrained WVGA , a 1024 meg WVGA, 1024 WXGA, and 1024meg 720p. There is a ‘base’ image for each, preconfigured, and ready to be deployed. The base emulator mages themselves can be found in C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v8.0\Emulation\Images .
Hyper-V must be installed somewhere to make this work. Let’s take a look at the Hyper-V control area. On the Windows 8 Start Screen, simply type in “Hyper-V” and you will see an entry for the Hyper-V Manager in the list of programs. Click on the icon to bring up the Hyper-V Manager. Once the Hyper-V manager starts, a list of virtual machines present on the machine you are on will be presented, along with a variety of control options. If you haven’t used Visual Studio to run any WP8 programs to the emulator (or manually configured any other virtual machines), the Hyper-V Manager will show a blank, empty surface in the list of VMs.
When you deploy a Windows Phone 8 program to one of the emulator, a number of things will happen. Firstly, Visual Studio will check to see if an instance of the emulator matching your target is already provisioned. If there is no image for the target deployment present, Visual Studio will deploy and provision the appropriate emulator image to Hyper-V. Below you can see the Hyper-V Manager after just one emulator image has been used. As you can see the emulator virtual machine is provisioned, and ready to go.
The .vhd will be copied from the SDK directory to the user’s AppData directory. The Phone SDK tools will run off the copy of the image. On my machine the image wound up in C:\Users\Joe\AppData\Local\Microsoft\XDE\dd.480x800.512.vhd . You can see this by going into the emulator settings for the image, and navigating over to the Name property. In the info displayed will be the location of the .vhd in use for that emulator image. Settings like memory amount and network adapter configuration will be added to the initial deploy.
If you deploy a program using each of the emulator targets in Visual Studio, a separate virtual machine will be created for each in Hyper-V. Walking though each vritual machine you might notice that all are configured for 1024 meg of ram. The exception to this would be the 512meg WVGA image. Also note if you go into network settings, all are configured for a Network Adapter of “Windows Phone Emulator Internal Switch”, which allows for the phone emulator to act on the same network as the users machine.
Power tip: I know some folks in our FLADEV group are working on games and chat clients to be used against other players in a real time fashion. Programming and debugging these scenarios can be difficult as you cannot have two instances of the same emulator running on the same machine. If you try and run two instance of the same emulator using Visual Studio you will get an error similar as shown below.
But…. If you start once instance of Visual Studio, and deploy to say the “512 WVGA Image”, then start another instance of Visual Studio and deploy to the “720p Image” you will be successful. You could use this configuration to simultaneously run and debug multi-client instances of the phone emulator. Below you can see four instances of the emulator image running at the same time, from four separate Visual Studio 2012 instances.
Hyper-V also has all four emulator images ready to go at this point as well. In the image below you can see all four, turned off, but at a state where the startup will be very fast as the provisioning and setup is complete.
Note this was possible in Visual Studio 2010 using the 7.1.1 SDK and a similar trick [ http://blogs.msdn.com/b/devfish/archive/2012/03/15/7-1-1-windows-phone-sdk-tech-preview-two-emulators-at-once.aspx ].
Power Tip : If you think your emulator image has gone “wonky”, delete it from Hyper-V when its not running. The next time you run to that image from Visual Studio 2012 it will re-provision Hyper-V.
Got any more tips ? Let me know in the comments below. The use of Hyper-V for the emulator might open up some interesting scenarios re snapshots, base lining an image, or other scenarios..
- Emulator in the MSDN Docs - http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff402563(v=vs.105).aspx
- Geert van der Cruijsen – 8 Days of Windows Phone – Day 4: New Screen Resolutions - http://vdcruijsen.net/2012/11/8-days-of-windows-phone-8-day-4-new-screen-resolutions/
- WP8 Emulator Troubleshooting Tips - http://social.msdn.microsoft.com/Forums/en-US/wptools/thread/b06cc9f2-aa5e-4cb3-9df1-0c273e1dfd68