Enabling Web Deploy from Visual Studio to an Azure Virtual Machine

web deploy-title pic

“Web Deploy is an extensible client-server tool for syncing content and configuration to Internet Information Services (IIS).”  This will allow you to publish your code directly from Visual Studio to IIS running on an Azure Virtual Machine (VM).  In order to accomplish this, some configuration and software are required to be installed on the VM.  The instructions for setting all of this up are spread out across several documents and there are a few difficulties that need to be overcome, below is described the entire process.

 

Prerequisites

The following three things are required to proceed:

  1. Create an Azure account, if you do not have one you can sign up for a free trial here
  2. If you do not already have Visual Studio installed, then install Visual Studio 2015 Community Edition, which you can download from here
  3. Install the .NET Software Development Kit (SDK) using the Web Platform Installer, which can be downloaded from here

 

Overview

There are a number of steps that need to be accomplished in order to deploy an application to an Azure VM using Web Deploy from Visual Studio:

  1. Create a Virtual Network
  2. Create a Virtual Machine in the Virtual Network
  3. Add the IIS Role to the Virtual Machine
  4. Install Web Deploy on the Virtual Machine
  5. Configure Permissions for Web Deploy in IIS
  6. Create an Application in Visual Studio and Publish it to the VM using Web Deploy
  7. Test the application

 

Step 1:  Create a Virtual Network

You will want to have a Virtual Network (VNET) where your VM will reside, so that in the future you can add additional VMs and they can all communicate together.  Below are the steps that I took to accomplish this:

  1. Go to the Azure Preview Portal and log in with your Azure credentials
  2. Click on ‘New’, then ‘Networking’, then select ‘Virtual Network’
  3. Under ‘Select a deployment model’ make sure ‘Classic’ is selected, then click ‘Create’.  Note:  I planned to create the VM in Azure using Visual Studio and discovered that (at this time) you must use the classic deployment model to do so.
  4. Give your VNET a name, Address space, Subnet name, Subnet address range, Resource Group, and location.  I used vnet4-kp as the name, rg4-kp as the Resource Group, ‘East US 2’ for the location, and left the remainder at the default values.
  5. Click ‘Create’

For reference, you can see a list of all the Azure Data Center locations here

 

Step 2:  Create a Virtual Machine in the Virtual Network

There are a number of ways that this can be accomplished, but I used Visual Studio:

  1. Open Visual Studio and log into your Azure account
  2. Open the Server Explorer tab, on the left
  3. After it has refreshed, right click on Virtual Machines and click ‘Create Virtual Machine’, this will open the Create New Virtual Machine wizard   web deploy-create vm1
  4. In the wizard, select your subscription and click Next
  5. Select your chosen Operating System (I chose the latest image of Windows Server 2012 R2 Datacenter) and click Next
  6. Enter a Virtual Machine name, size, user name, and password for your VM (I used VM1-kp, and a small VM), then click Next
  7. Under Cloud Service, select create new and choose a name and location for your Cloud Service (I used ‘csvm1-kp’ and East US 2)web deploy-create vm2
  8. Under Virtual Network, choose the VNET you created earlier
  9. Leave the Subnet(s) at default
  10. Under Storage Account, select ‘create new’ and input a name and region, then change the replication to locally redundant.
  11. Click Next
  12. For Endpoints, add the following using the ‘Port Name’ drop down box and the add button:  Web Deploy, HTTP, and HTTPS.  This will add one for port 8172, one for port 80, and one for port 443 (we will use these later for SSL connections).
  13. For ease of use, change the public port for Web Deploy to 8172 and the public port for Http to 80, then click Createweb deploy-create vm3
  14. The provisioning process will begin and this may take 10-15 minutes, so be patient

 

Step 3:  Add the IIS Role to the Virtual Machine

Adding Internet Information Services (IIS) and various connected components to a server turns it into a Web Server.  This needs to be done in order to run web applications on the server.  Below are the steps that I took to accomplish this:

  1. Log into the Azure Management Portal
  2. Click on Virtual machines (classic).
  3. Click on the VM that was created above
  4. Click the ‘connect’ button, run the .rdp file that is sent, and follow the on screen prompts to log into the VM with Remote Desktop
  5. Server Manager will open when you log in, click on ‘Add roles and features’ near the top
  6. Click Next
  7. Make sure ‘Role-based or feature-based installation’ is selected and click Next
  8. Make sure ‘Select a server from the server pool’ is selected and click Next
  9. Select ‘Web Server (IIS)’ from the list of Roles
  10. Click ‘Add features’ from the new window
  11. Click Next on the next 4 screens, then click Install
  12. Wait until installation is complete, then click Close

 

Step 4:  Install Web Deploy on the Virtual Machine

  1. Disable IE Enhanced Security Configuration by clicking on ‘Local Server’ in the Server Manager, then click ‘On’ next to the setting and change the setting to off for administrators
  2. Open the charms on the right side of the screen and select search, then type in Internet Information Services, click on the result in the list (this will open Internet Information Services (IIS) Manager
  3. Click on the triangle to the left of the VM listed in the Connections Menu
  4. When the popup asks if you would like to stay connected with the latest Web Platform components, click Yes.  This will open the site to install the Web Platform Installer.  Click on the Free Download button and run the installer.
  5. In the search bar for the Web Platform Installer type Web Deploy
  6. Click ‘Add’ for all three of the Web Deploy 3.5 components, click install, and accept the terms of use, then wait for the install to complete
  7. Reboot the VM

 

Step 5:  Configure Permissions for Web Deploy in IIS

You will need to give yourself permission to use Web Deploy in IIS before you can publish to the VM from Visual Studio.  The instructions for this are below:

  1. If you are proceeding immediately from the section above, wait for the VM to reboot the log back into it with Remote Desktop
  1. Open the charms on the right side of the screen and select search, then type in Internet Information Services, click on the result in the list (this will open Internet Information Services (IIS) Manager
  1. Click on the triangle to the left of the VM listed in the Connections Menu
  2. When the popup asks if you would like to stay connected with the latest Web Platform components, click No this time
  3. Click the triangle next to Sites in the menu on the left
  4. Click On Default Web Site
  5. In the list of functions in the middle of the page, scroll down to the management section and double click on IIS Manager Permissions
  6. On the right, click on ‘Allow User’
  7. In the Windows “type of user” click the select button
  8. In the ‘Enter the object name to select’ text field type your user name for the VM and click check names (it should change it to the format of {vm name]\[user name]), then click OK.
  9. Click OK again and close the Internet Information Services (IIS) Manager
  10. You are now ready to Web Deploy to the VM (see below)

 

Step 6:  Create an Application in Visual Studio and Publish it to the VM using Web Deploy

Now we just need to create a simple application in Visual Studio, publish it to the VM using Web Deploy, and then test to be sure it is working – please see the instructions below:

  1. Start Visual Studio and log in with your Azure account
  2. Go to File -> New -> Project and select Cloud -> ASP .NET Web Application
  3. Then change the name if you wish (I used testWD) and click OK
  4. Under ASP .NET 4.5.2, select the Empty template
  5. Under Microsoft Azure in the lower right, select Virtual Machine v1 from the dropdown box and click OK
  6. As this is just a simple test, we will keep it simple. Right click on the project in solution explorer, go to Add, the add an HTML page and name it defaultweb deploy-create app1
  7. On the HTTP page that opens, add the text ‘Hello World’ between the <body></body> tags
  8. Build the solution
  9. Right click on the project and select ‘Publish’
  10. In the Publish Web Profile that opens, select More Options, then click Microsoft Azure Virtual Machines
  11. Wait for the list to load, then select the VM that you just created and click OK
  12. Now you will see the connection properties, add the user name and password that you created for the VM, but leave everything else as it isweb deploy-create app2
  13. You can click ‘Validate Connection to test the connection to the VM and if all is well, click ‘Publish’

 

 

Step 7:  Test the Applications

  1. Open a web browser and got to the following web address: {The cloud service name you chose}.cloudapp.net/default.html
  2. In my case this wound be:  csvm1-kp.cloudapp.net/default.html
  3. You should see the Hello World responseweb deploy-test app1
  4. CELEBRATE!

Leave a Reply