Author: Joe Nalewabau
Windows Azure Tools for Microsoft Visual Studio extend
Visual Studio to enable the creation, building, debugging, running and
packaging of scalable services on Windows Azure.
You can create a new Cloud Service using the New Project
dialog in Visual Studio and selecting the “Cloud Service” template.
This will bring up a dialog which enables you to add Web and
Worker roles to your Cloud Service.
.jpg)
If you create a Cloud Service that contains a Web Role and
Worker Role, your project structure will look similar to the one below:
.jpg)
The Cloud Service project:
- Builds and packages your Cloud Service for the
Development Fabric
- Provides Run and Debug functionality in the
Development Fabric
- Publishes your package to the Windows Azure Service
Package format
- Enables you to configure the roles and role
projects in the Cloud Service
This document will walk through using the Roles node in the
Cloud Service project.
Inside the Cloud Service project you will see a node called
“Roles”. The Roles node provides a graphical view of the Visual Studio projects
that are associated with the roles defined in the Service Definition file
(ServiceDefinition.csdef).
You can use the Roles node to:
- Change the project associated with the Web or
Worker role in your Cloud Service
- Add or remove roles from your Cloud Service
- Set Role properties
Changing a project associated with a role
At some stage you might want to change the project
associated with a specific role in your cloud service. You have two options:
- Associate a role with a new project
- Associate a role with an existing project
Associate a role with a new project
In order to create a new project for a specific role in your
cloud service, you:
- Open the Roles node in the Cloud Service
- Right click on the existing node you want to
change the project association and choose “Associate with->New … Project”
(note that the menu item text changes to reflect the role type)
- The New Project dialog is displayed with the
appropriate project template for the Role type you selected.
- Name the project and hit OK
- A new project is created for you in the solution
- The Roles node is updated to show the
association to the newly created project
- The previous project associated with the role
remains in the solution.
Associate with an existing role project
In order to associate an existing project with a specific
role in your cloud service, you:
- Load or create the role project you want to
associate into the same solution as your cloud service.
- Right click on the existing node you want to
change the project association and choose “Associate with->… Role project in
solution” (note that the menu item text changes to reflect the role type)
- The “Associate with Role Project” is displayed.
This dialog lists the projects in the current solution that have the same Role
type as the role you are changing.
- Choose the project you want to associate the
role with and hit Ok.
- The roles node is updated to display the project
association
- The previous project associated with the role
remains in the solution.
Add or Remove Roles from a Cloud Service
You can also use the Roles node to add or remove roles from
a Cloud Service. While you could do this directly in the service definition
file, using the Roles node allows Visual Studio to update the Service Configuration
file at the same time.
Adding a Role to a Cloud Service
Adding a role to Cloud Service is simple, right click the
Roles node in a Cloud Service and select the type of role you want to add to
your cloud service.
Note that you have an option to add a new project for that
role or use an existing role project. Once a role is added to the cloud
service, the appropriate entries are also made in the service configuration
file.
Removing a Role from a Cloud Service
Removing a role from a Cloud Service is simple, right click
the role you want to remove and select “Remove”. Visual Studio will remove the
role from the service definition as well as any service configuration entries
for that role.
Note that removing a role in a cloud service does not do
anything to the project currently associated with that role – removing simply
removes the association between the role and that project.
Setting Role Properties
Select one of the Role project associations under the Roles
node, right click and select “Properties”.
.jpg)
This will allow you to use the Properties Window to set
properties on the Role such as enabling full trust or setting the instance
count.
.jpg)