Extracting Files from the Windows Phone 8.1 Emulator

If you have done any Windows Phone development, you know that the emulator resets each time it closes.  This restores the emulator to its original state, removing any settings and data.  This is a good thing since you have a consistent starting state to develop your app. It can also make developing your app a little awkward, especially if you need to verify behavior against the underlying data.

In my case, I had a SQLite database I wanted to verify, which meant figuring out where the DB file was being stored.

Finding the Emulator’s Virtual Disk

The first thing you need to extract files out of the emulator is to find where it stores its virtual hard disk.  If you open the Hyper-V Manager and select your computer on the left, you should see a list of virtual machines.  The Windows Phone Emulator should be obvious, although depending on your settings it may be different from mine (shown below).  Note that I have two emulators – one for WP8 and the other for WP8.1, so be sure to select the one you need.  If you can’t figure out which VM is the emulator, simply run it and find the machine with a “Running” state.

image

Select the emulator and check out the Notes section at the bottom.  That should have the location and name of the VHD file.  If not, you can click on the “Settings” option to bring up the settings window.  From there navigate to “IDE Controller 0”, then “Hard Drive” and you should find the location of the virtual disk under “Media” on the right.

image

Reading an AVHD File

Once you know the name and location of the virtual disk used by the emulator, you can open it in explorer and mount the VHD by right-clicking the file and selecting “Mount” (make sure the emulator is not running).  This will mount several partitions, unfortunately, none of them will contain the data you need.

Instead, you must look for an AVHD file that begins with the same name as the VHD file (which you can unmount by right-clicking on any of the mounted partitions and selecting “Eject”).  The AVHD file contains all the changes to the disk made during the last run of the emulator.  These changes will be overwritten each time the emulator is started, so you may want to make a copy of this file if you want to preserve the state.

By default, windows does not know how to handle an AVHD file, but you can trick Windows into mounting it by simply changing the extension to VHD.  Mounting the AVHD file will again cause a number of partitions to be mounted, one of which is called “Data”.  Hopefully you know the name of the file you are searching for, and can simply search for it using the search bar.  If you are using the local app data store, that should be somewhere along the lines of:

M:\Users\DefApps\APPDATA\Local\Packages\<APP IDENTIFIER>\LocalState

You will likely need to take ownership of the “Users” folder before Windows will allow you to access the directory and files though.

Copy and Go

Now that you know where your files are and have taken ownership, you can copy them back into your physical drive, eject the AVHD file, and (if you decided not to make a copy) rename the file to its original AVHD extension.  You can then take a look at the data at your leisure – just remember the next time you start the emulator it will overwrite the AVHD file.