Development
Now Reading
Visual Studio: how to run Windows Phone and Android emulators in a virtual machine
0

Visual Studio: how to run Windows Phone and Android emulators in a virtual machine

by Guglielmo MengoraJanuary 6, 2017

If you’re anything like me, virtualization has a great and important role in your everyday work. I use to virtualize most of my development machines, with Visual Studio and the whole stack. That allows me to avoid reconfiguring the environments whenever I need to switch my main machine, plus you get all the benefits of virtualization like for example the ability to backup the whole machine and move it elsewhere.

Up until now, such deployments had just one limitation: you could not use them to run mobile apps since nested virtualization was not supported on Windows 8 or Windows Server 2012 R2 so you could not run emulators that needed Hyper-V. Things changed with Windows 10 and Windows Server 2016 since nested virtualization is now allowed so I thought that was perfect chance to redeploy machines I used for mobile development into VMs.

So Visual Studio 2015 is running and Xamarin ready, you create a new Xamarin Forms project and you want to test that your environment is working fine. You start debug for the Android application but the Visual Studio Android emulator is not working. A “Hyper-V component is not running” :

Something happened while starting a virtual machine: ‘VS Emulator 5-inch KitKat (4.4) XXHDPI Phone.macoswin’ failed to start. (Virtual machine ID 77D02994-C4A1-4A43-9AE7-7E55C03521D4) The Virtual Machine Management Service failed to start the virtual machine ‘VS Emulator 5-inch KitKat (4.4) XXHDPI Phone.macoswin’ because one of the Hyper-V components is not running (Virtual machine ID 77D02994-C4A1-4A43-9AE7-7E55C03521D4). _

Hyper-V seems to be working fine plus it has been installed, something that never succeeded in past Windows (Server) versions but emulators don’t work. The reason for this is your host is not enabling all Hyper-V features to the guest machine. That’s probably related to the fact that Hyper-V is also needed for Containers but I’m not sure about that.

Turns out that you need to tell host that you want to expose ALL Hyper-V functionalities if you want to enable full nested virtualization so you have to log into the host (which might simply be your own notebook or desktop PC or even a Surface Pro, like in my case) and run this command using an elevated shell:

 
 Set-VMProcessor -VMName <VMName> -ExposeVirtualizationExtensions $true

<VMName> obviously is the name of the virtual machine that you want to enable nested virtualization for. Also ensure that such VM has been shut down (no saving, no suspension). Once you reboot, emulators will start working. You might need to re-deploy the emulators VMs just to ensure that everything will be redeployed in a smooth way. You simply need to delete those emulators inside Hyper-V Manager.

The problem is: when you will deploy your test app – even the simplest one, the one generated by the template – it will not run inside the emulator. It just starts and shuts down almost instantly, probably crashing.

To fix this problem, you need to change a setting in the virtual machine that is hosting Visual Studio and the emulators as well:

Hyper-V emulators setting

Again, you need to shut the VM down before changing this setting. Once done, reboot and deployment for your application should start working.

Now you can see your virtual machine for mobile development as well.

Just remember that you need Windows 10 with Anniversary Update or Windows Server 2016 as both host and/or guest systems. You also need that machine to be upgraded be using v8 configuration files and, obviously, an Intel CPU that supports VT-x and EPT extensions.

Read full documentation here.

What's your reaction?
Love It
100%
Interested
0%
Meh...
0%
What?
0%
Hate it
0%
Sad
0%
Laugh
0%
Sleep
0%
About The Author
Author Image
Guglielmo Mengora

Leave a Response