Thursday, November 21, 2013

Building a Windows 8.1 Developer Environment in Windows Azure

This article was based on the article Step-by-Step: Building a FREE Windows 8 App Dev Lab in the Cloud with Windows Azure Virtual Machines by Keith Mayer. His article pertains to Windows 8 app development in Windows Server 2012; I was able to use the same process to develop Windows 8.1 apps in Windows Server 2012 R2.

No Windows 8 or 8.1, No Problem

With Windows 8/8.1, there is a lot of excitement floating around for developers that want to get their feet wet in Windows 8 app development. However, if you plan on building these apps you will need either Visual Studio 2012 on a Windows 8 platform or Visual Studio 2013 on Windows 8.1 platform.
If you plan on building Windows 8.1 apps, you will need Visual Studio 2013. Please note that VS 2013 only builds Windows 8.1 apps, not 8, and VS 2012 only builds Windows 8, not 8.1 as far as I know.
Now what if you don't have Windows 8.1, or in my case, you just upgraded to Windows 8.1 and your hard drive crashed? Then you're SOL Jon...since this is a blog about Microsoft Technologies, I took this as an opportunity to play with Windows Azure's Virtual Machines service a bit.

Setting up the Virtual Machine

By using VMs in Microsoft's cloud environment, we don't have to use our own computer resources, where as with a VHD image on your box, you're allocating space on your crashed hard drive, eating away at your pathetic 1gb of memory, etc. There are better things to use that space for...like your 80's movies collection.
Back on topic, we want to use a VM to create a Windows 8.1 image, but not so fast -- you can't run VMs in Azure with Windows Desktop OSs, only Server OSs. Surprise, surprise
As a workaround, we can develop Windows 8.1 apps in Windows Server 2012 R2 (or Windows 8 apps in Windows Server 2012) with a few tweaks. Let's get started:
First, we'll need to create a VM with a Windows Server 2012 R2 image:
In your Windows Azure Portal, click +New button -> Compute -> Virtual Machine -> From Gallery
Create New Virtual Machine From Gallery
Select Windows Server 2012 R2 Datacenter on the "Choose an Image" window.
Select Windows Server 2012 R2 Datacenter Image
Complete the prompts that follow to complete your Virtual Machine configuration.
I set my Virtual Machine Size to Large (4 cores, 7GB memory). I haven't had any problems at all, but I would recommend at least a Medium (2 cores, 3.5GB memory) size to prevent any frustration and keyboard smashing from lagging.
Once completed, your VM will begin provisioning to finish preparing the image and VM for your use. In the meantime, make yourself a milkshake...you deserve it for taking a step into a new big world. The VM's status will display as "Running" when ready for use.

Setting up Windows Server 2012 R2 for Development Use

Out of the box, you won't be able to develop Windows 8.1 apps in Windows Server 2012 R2. It's not only because you haven't installed VS 2013 yet, but without a little tweaking you won't be able get a Developer Licenses on Windows Server 2012 R2 because they aren't available for the Server OSs. Please note, that this work around is for development purposes only. If you are planning to publish your app, please do so by building and publishing on an actual Windows 8/8.1 platform. Back to the tweaking:
Okay, we want to connect to our newly built VM. To do so -- in your Windows Azure Portal click the "Virtual Machines" tab -> Highlight the VM -> Click Connect
Connect to new VM when Running
When prompted any Remote Desktop Connection Security Warning, allow the connection/validate the certificate. When prompted for credentials, enter the same one used when creating the VM.

Create New User for Development

You must create a separate user account for developing, because the Built-In Administrator account can't be used to build code in Visual Studio.
To create this developer user account, do the following:
After you've logged on, open Server Manager (if not opened already) -> Click Tools in the upper-right corner of the application -> Select "Computer Management"
In the "Computer Management" screen -> Expand "Local Users and Groups" -> Right-click "Users" -> Select "New User..."
When creating your user, make sure the "User must change password at next logon" and "Account is disabled" options are NOT checked. Click Create then Close.
Adding New User
Now let's add the new user account to the Admin group so it will have the right permissions.
In the "Computer Management" screen -> Expand "Local Users and Groups" -> Select "Groups" -> Right-click "Administrators" group -> Select "Add to Group..." -> Click "Add" in the properties window -> Add the new user and Click Ok to apply the changes.
Adding User to Administrators Group

Configure Services

Open Server Manager -> Click Tools in the upper-right corner of the application -> Select "Services"
In the "Services" screen -> Double-click "Windows Audio" service -> For Startup Type, Select "Automatic" -> Start Service -> Click Ok
In the "Services" screen -> Double-click "Windows Audio Endpoint Builder" service -> For Startup Type, Select "Automatic" -> Start Service -> Click Ok
Windows Audio and Windows Audio Endpoint Builder Services

Change IE Enhanced Security Configurations

In order to use IE as you typically would in a Desktop OS, we need to turn off the IE Enhanced Security. To do so:
Open Server Manager -> Click "Local Server" in the left navigation panel -> Click "IE Enhanced Security Configuration" on the right side of the page -> Set "Administrators" and "Users" options to "Off" -> Click Ok
Turning off the IE Enhanced Security

Update Registry for IE

To open the Registry Editor, search for "Regedit" and select the application.
In the "Registry Editor" application -> Navigate to the following path location: 
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main
Double-click "ApplicationTileImmersiveActivation" -> In edit window, set "Value Data" to 1 -> Select the "Decimal" option -> Click Ok
Updating registry for IE

Activate Desktop Experience Feature

In order to have the OS operate similar as Windows 8.1 and have the look and feel, we must activate the "Desktop Experience" feature for the Windows Server OS.
Open Server Manager -> Click "Manage" in the upper-left corner of the application -> Select "Add Roles and Features"
In the following windows, click Next until you get to the "Features" window. Here we will:
Expand "User Interfaces and Infrastructure (Installed)" -> Check the "Desktop Experience" checkbox -> When prompted, Click Add Features -> Click Next then Install -> After completion, restart the VM from your Windows Azure Portal
Installing Desktop Experience Feature
Restart the VM

Install Microsoft Visual Studio 2013 and Windows 8.1 SDK

When logging back into your VM, use the new user account you created in the previous steps (you can use this account from here on out. You will not be able to debug/compile using the Built-in Administrator account).
Keep in mind, if you will be developing Windows 8.1 apps, you need VS 2013. For developing Windows 8 apps, you need VS 2012.
Install VS 2013 however you like, I used VS 2013 Ultimate edition but you can use the Express edition also. After the installation of VS 2013, you will need to restart your VM again.
After restarting and logging back in with your new user account, download and install the Windows 8.1 SDK from here:
http://msdn.microsoft.com/en-us/windows/hardware/bg162891.aspx

Windows 8.1 SDK

Obtain Developer License for App Development

When launching VS 2013 for the first time, you should be prompted to "Get a developer license..." If so, accept and enter your Microsoft Account credentials to obtain your developer license. If you're not prompted, when the VS home page loads create a new Windows Store application. After the solution loads, click "Project" in the toolbar -> Highlight "Store" -> Select "Acquire Developer License..."
Acquire Developer License in Project
License Obtained
Now you can "officially" start developing a Windows 8.1 app without a Windows 8.1 OS. Use this Windows 8.1 in C#/VB Tutorial provided by Microsoft to get started.
Building Windows 8.1 App
Executing Windows 8.1 App on Windows Server 2012 R2

Final Tips: Saving Compute Charges in Azure and VS Online

As long as your VM is running, it is accumulating compute charges. If you want to save your money, and prevent unnecessary charges when not using the VM, shut down the VM when not in use.
Make sure to shut down your VM using the Windows Azure Portal to prevent compute charges. If you shut down from within the VM, the VM will be "Stopped" but still accumulate compute charges. Shut down in the Windows Azure Portal, and make sure the status is "Stopped (Deallocated)" to prevent compute charges, otherwise you'll pay the price. 
If you are familiar with Team Foundation Server, you know it is a great collaboration tool and you'll love this. Visual Studio now offers a hosted TFS environment online called VS Online. A great use of this is having the collaboration aspect, if needed, but also having an online repository at your disposal. So after you get your laptop back with a new working hard drive...you can grab your project and source code as you please from VS Online. There are many other benefits to using VS Online, check it out.
TFS is now VS Online
Happy Coding!!

Resources