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.
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.
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:
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.