Azure Cloud Services - Project File Details

This article is a part of a series of articles related to one of the Azure Compute options, “Cloud Services”.

 

In this article, we will learn about the files that get created when we create an Azure Cloud Service Project.
  • Roles

    • As we have created an empty Azure Cloud Service Project, we have an empty “Roles” folder. In general, this folder contains all the codebase related to the Web Roles and the Worker Roles.

  • XML Files

    • ServiceConfiguration.Cloud.cscfg
    • ServiceConfiguration.Local.cscfg
    • ServiceDefinition.csdef

Let’s examine each of the above XML files individually.

ServiceDefinition.csdef

This file is called Service definition and contains all the details about the Cloud Service. It contains the details of Web Role(s) and Worker Role(s). This file defines the service model of the application. Based on the information provided in this file, the App Fabric Controller creates everything required for the application.

  1. The size of the Virtual Machine instance where the roles are hosted.
  2. The endpoints information (We will learn more about these endpoints in upcoming articles).
  3. Traffic rules (We will learn more about these in upcoming articles).
  4. Other configuration settings, like connection strings etc.

Below are the default settings that are created when the Azure Cloud Service project is created.

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <ServiceDefinition name="HelloWorldCloudService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2015-04.2.6">  
  3.     <WebRole name="FrontEnd.Web" vmsize="Small">  
  4.         <Sites>  
  5.             <Site name="Web">  
  6.                 <Bindings>  
  7.                     <Binding name="Endpoint1" endpointName="Endpoint1" /> </Bindings>  
  8.             </Site>  
  9.         </Sites>  
  10.         <ConfigurationSettings>  
  11.             <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" /> </ConfigurationSettings>  
  12.         <Endpoints>  
  13.             <InputEndpoint name="Endpoint1" protocol="http" port="80" /> </Endpoints>  
  14.     </WebRole>  
  15.     <WorkerRole name="WorkerRole1" vmsize="Small">  
  16.         <ConfigurationSettings>  
  17.             <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" /> </ConfigurationSettings>  
  18.     </WorkerRole>  
  19. </ServiceDefinition>  
ServiceConfiguration.cscfg

This file is called as Service Configuration file and contains the configuration details of the Web Role(s) and Worker Role(s). Service Configuration files are similar to Web.Config file (for Web Apps) and App.Config files (for Windows Apps), 
  1. The OS family of the Virtual Machine where the Roles are hosted.
  2. The OS Version of the Virtual Machines.
  3. The number of instances in which the Roles are to be hosted.

If you have noticed clearly, there are two versions of the Service Configuration files in the root folder of the project.

  • ServiceConfiguration.Cloud.cscfg
  • ServiceConfiguration.Local.cscfg

One is tagged for Cloud and the other is tagged to be used in the local environment. These are two files that are created by default. We can also create additional files for our other environments, like Staging, Testing etc.

Below are the default settings that are created when the Azure Cloud Service project is created.

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <ServiceConfiguration serviceName="HelloWorldCloudService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2015-04.2.6">  
  3.     <Role name="FrontEnd.Web">  
  4.         <Instances count="1" />  
  5.         <ConfigurationSettings>  
  6.             <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" /> </ConfigurationSettings>  
  7.     </Role>  
  8.     <Role name="WorkerRole1">  
  9.         <Instances count="1" />  
  10.         <ConfigurationSettings>  
  11.             <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" /> </ConfigurationSettings>  
  12.     </Role>  
  13. </ServiceConfiguration>  
Few important points to note are:
  • If there are any changes to the Service Definition file, after your Cloud Service has been deployed, you have to re-deploy your Cloud Service package. (We will learn more about the Cloud Service package in my upcoming articles).
  • If there are any changes to the Service Configuration files after you deploy the Cloud Service, you have no need to re-deploy your entire Cloud Service package. You can simply upload your Cloud Service Configuration (.cscfg) file or simply make that change in the portal directly.

If you have observed carefully, the configuration settings are also defined in the Service Definition file. So, you cannot simply add or remove these settings. Below is the setting name that I am talking about Service Definition File.

  1. <ConfigurationSettings>  
  2.     <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" /> </ConfigurationSettings> Service Configuration File – The following tag is being referred in both the Web and Worker Roles.  
  3. <ConfigurationSettings>  
  4.     <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" /> </ConfigurationSettings>  
The setting name in the Service Configuration file should be the same that is specified in the Service Definition file. Let’s try to comment out the following tag in the Service Definition file and see what happens.
  1. <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" />  
Below is the error that I got after commenting out the above line in the Service Definition file.

So, in order to add a new Configuration setting in the Service Configuration file, you have to first add the name of that setting in the Service Definition file and then use the same in the Service Configuration file.

Hope you enjoyed the article. Your feedback is much appreciated.

Up Next
    Ebook Download
    View all
    Learn
    View all