Tuesday, 23 August 2011

Publishing to Azure environment directly from Visual Studio (with Azure SDK v1.4)

Windows Azure SDK v1.4 gives different options for Publishing and Packaging the Azure applications. The same concept was already exists with Azure SDK v1.3, but both are combined with only one option ie., menu and popup window.

In Visual Studio, when right click the Azure Project there will be two menus,
  1. Package – for creating .cspkg and .cscfg file which can be uploaded to cloud anytime using Management Studio. This we can call it as Manual publish.
  2. Publish – for publishing directly to Azure environment from Visual Studio.

This post gives a walkthrough of how to publish Azure applications directly from Visual Studio using Azure SDK 1.4.

  1. Prepare the Azure Project

    I am taking a sample fresh new Web Role Application for demo purpose.

  2. Create Hosting Service from Management Portal

    Before deploying any application to Azure environment from Visual Studio, it is required to create a Hosting Service for that. When creating Hosting Service, there is no need to upload the package for the service as the deployment done by Visual Studio. So select Do not deploy option in the Create a New Hosting Service window and Deployment name, Package Location and Configuration file inputs are not required.


    If the Hosting Service already created before, it is possible to link the service from Visual Studio. The requirement here is to have a Hosting Service before deploying the service from Visual Studio.

  3. Create Certificate when publishing the Azure application.
    Certificate is used to authenticate the Publishing from Visual Studio. So the certificate must present in Management portal and also the system where the application is getting published from Visual Studio. The certificates can be created for Azure in three ways.
    1. Using makecert.exe command line. Open the Visual Studio Command Prompt and type the following command to create the certificate.
      makecert -sky exchange -r -n "CN=<CertificateName>" -pe -a sha1 -len 2048 -ss My "<CertificateName>.cer"
    2. Create the certificate using IIS manager.
      Open IIS manager (inetmgr) and create certificate using Create Self-Signed Certificate option from Server Certificate section.
    3. Create from the Visual Studio popup window itself when publishing.

    The first two options may bring extra work for us, but it provides naming to certificate which is useful for distinguishing the certificates. But when creating from the Visual Studio popup option, the name of the certificate will be Windows Azure Tools only. It becomes difficult to know which certificate linked to what (by using Thumbprint only possible to distinguish).

    It is developer option to follow any of these options. The below step takes the third option, creating certificate on publishing window. But if you have already created certificate, select the certificate instead of creating it.

    1. Right click the Azure application and select Publish option. It will open Publish Windows Azure Application window.
    2. From the popup window, select <add> option from Credentials dropdown box.
    3. It will popup Windows Azure Project Management Authentication window.
      Select Create from Create or select an existing certificate for autentication dropdown. (Incase if you already created the certificate using makecert.exe or IIS manager, select the certificate.)
    4. Select Create. It will prompt to enter Certificate Name.

      Enter Certificate Name and Press OK.
    5. In the Windows Azure Project Management Authentication window copy the full path of the certificate by selecting Copy the full path link. (Note: The certificate will be stored in this location. This path is required to select the certificate and link in Management Portal)



    6. Before doing any further action, it is important to link the certificate in Azure Management Portal. So after uploading the certificate in Management Portal, we can resume this publish.
  4. Uploading Certificate in Management Portal
    1. Open the Management Portal and select the Subscription. Note Subscription ID from the Properties of the service from right section.


    2. In Management Portal select Management Certificate. The portal will show list of subscription and the certificate in the center section.
    3. Select Add Certificate option from the top of the screen.


    4. In the Add New Management Certificate window, select the subscription and select the certificate file where the path selected from Visual Studio.
      (Press Browse button, the system will open Browse window. Paste the full path copied from Copy the full path link from Azure Project Manegement Authenticate window and selects the Certificate located in that location with the Certificate Name entered before.



    5. Once the certificate created the certificate will be listed under the subscription name at Management Certificate option.


  5. Publish the Azure Project

    Now the certificate linked with the Management Portal. This step resumes from Step 3 i.e. Windows Azure Project Management Authentication window.

    1. Enter the Subscription ID. The Subscription ID already noted while uploading certificate.
    2. Provide any friendly name for Name these credentials and press OK.

    3. In the Publish Windows Azure Application window, Credential dropdown box will be selected with the name we just selected. The Windows Azure environement dropdown box will be filled by fetching all the hosting services created under the subscription from Azure environement. Select the hosting service on which the publish should happend.

    4. Incase if you are using any storage account for the application, select the account from the Publish storage account. If not, select any one by default.
    5. The Service configuration dropdown box lists Cloud or Local.
      From Azure SDK v1.4, there are two configuration files will be created in the cloud project.
      ServiceConfiguration.Local.cscfg - contains the local emulator configuration.
      ServiceConfiguration.Cloud.cscfg - contains the azure environment configuration.
      This lets the Visual Studio to let know which configuration file needs to move to cloud environmenet.
    6. Select the build configuration from Build configuration dropdown.
    7. Give some friendly name for labeling the Publish if required.
    8. Click Publish to publish to cloud.
Visual Studio will authenticate with the Management Portal certificate and upload the package directly to Azure environment.
There will be a popup for your confirmation if there is already an application running with the same hosting service in Azure environmenet. Click Delete and Continue if the publish needs to overwrite the current application.

It will starts publishing to Azure environment from Visual Studio. You can verify the status of publish from Visual Studio or from Management Portal. The management Portal will show the progress which is going on at the selected Hosting Service once the Visual Studio uploaded the package and started the process. Below figure shows the status both in Visual Studio and Management Portal at same time.







0 Responses to “Publishing to Azure environment directly from Visual Studio (with Azure SDK v1.4)”

Post a Comment