• 3 min read

How to Provision and Deploy Multiple Websites from your Cloud Deployment Project

Learn how to use the Cloud Deployment project to dynamically generate the resources and deploy the applications to those resources.

The Cloud Deployment project is extremely useful, in that it gives us a quick way to get a website up and running allowing us to focus on the development of the web application and not how to get it provisioned and deployed into Azure. Normally, people have more than one website they are working on at a time so, that is what we will focus on today.

Create new Cloud Deployment project

For this demonstration the first step is to create a new Cloud deployment project with a Website. If you haven’t done this before take a look at the Azure Resource Manager 2.5 for Visual Studio.

Here is a quick guide to create the initial Cloud Deployment project.

NewProject

Select the type of deployment. For this example I chose “Website.”

SelectWebsite

Then select the type of ASP .NET project. I chose the MVC option.

ASPNetSelect1

Now you have your initial Cloud Deployment project created.  Now to add a second ASP .NET Web Application to solution.

NewWebProject

Again I’ll chose the MVC project, making sure to NOT check the “Host in the cloud” option.

ASPNetSelect

Once you have it added, we’ll look at what needs to occur to connect it to the deployment project.

Connecting second web application to deployment project

The first step is to add a new reference to the .deployment project and check the newly added web application.

AddReference

This will let the deployment project know that there is another web application and to generate information on the web deployment package, location, and what to do with the web application at deploy time. Right now there are only two options: Build and Package.  The package location information can be reused later in the JSON, but we’ll get to that eventually.

ReferenceProperties

Now we jump into editing the JSON information, so open up the WebSiteDeploy.json file.

There are two sections that we’ll look at, the “parameters” and the “resources”. We want to add (cut/paste and modify) new versions of the “webSitePackage” and “webSiteName” make sure to name them something original, like “websitePackage2” and “webSitename2”.  I’ve highlighted the original section in the editor and added the updated JSON below.

JSONProperties

 

Here is the JSON. Two key things to notice are  the changes in the package defaultValue name and the parameter name are both set the “2” version.

  "webSitePackage2": {

    "type": "string",

    "metadata": {

      "visualStudio.deployment": { "parameterUsedAs": { "value": "projectOutput" } }

    },

    "defaultValue": "MyAzureCloudApp2/package.zip"

  },

  "webSiteName2": {

    "type": "string"

  },

In the resources section, we’ll need to add (cut/paste and modify) the “Microsoft.Web/sites” resource fragment. Make sure to modify the parameters to webSitename2 and webSitePackage2. The web deploy extensions fragment nested in the site resources gets the web deploy package from the drop location and loads it onto the Azure resource.

JSONresources

Here is the JSON fragment.

{

  "apiVersion": "2014-06-01",

  "name": "[parameters('webSiteName2')]", 

  "type": "Microsoft.Web/sites",

  "location": "[parameters('siteLocation')]",

  "tags": {

    "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "Resource"

  },

  "dependsOn": [

    "[concat('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"

  ],

  "properties": {

    "name": "[parameters('webSiteName2')]",

    "serverFarm": "[parameters('hostingPlanName')]"

  },

  "resources": [

    {

      "apiVersion": "2014-04-01",

      "name": "MSDeploy",

      "type": "extensions",

      "dependsOn": [

        "[concat('Microsoft.Web/Sites/', parameters('webSiteName2'))]"

      ],

      "properties": {

        "packageUri": "[concat(parameters('dropLocation'), '/', parameters('webSitePackage2'), parameters('dropLocationSasToken'))]",

        "dbType": "None",

        "connectionString": "",

        "setParameters": {

          "IIS Web Application Name": "[parameters('webSiteName2')]"

        }

      }

    }

  ]

},

Save it all off and deploy it.  You can do this from the Deploy context menu from the .deployment project, and the Deploy to Resource Group looks the same as any other deployment.  Select the subscription, resource group (or create it), and storage accounts.

DeployToResourceGroup

But  if you edit parameters, you will have the new parameters for the second website.   With this example, I’m using the same hosting plan and location, but this can be changed by copy/pasting the necessary resources in the JSON file.

Parameters

Once deployed, the Output window will show that both sites have been deployed, as seen below.

DeployedSites

Just to confirm that everything worked as it should, you can either open the Azure Portal or from within the Visual Studio IDE open the Server Explorer window, expand the Website node and see that both sites are up in the cloud.

Here is a nice close up.

ServerExplorer

Hopefully this makes your day a little easier!

Please let us know what you think by completing this survey.

Thanks,

Roger