Step-by-Step: How to Publish to Windows Azure (Andy Kung)

UPDATE: These steps have been simplified with the release of Visual Studio 2012. Please see: Publishing LightSwitch Apps to Azure with Visual Studio 2012


One of the many features introduced in Visual Studio LightSwitch Beta 2 is the ability to publish your app directly to Windows Azure with storage in SQL Azure. We have condensed many steps one would typically have to go through to deploy an application to the cloud manually.

In this tutorial, we will deploy a LightSwitch web application with Forms authentication to Windows Azure and SQL Azure. This walkthrough assumes that you already have a Windows Azure subscription and basic knowledge of Windows Azure. If you do not have a subscription, you can sign up for an account here. The sign up page will explain different pricing models as well as a Free Windows Azure trial!

Configuring Windows Azure

Before we publish an application from LightSwitch, let’s first make sure we have the necessary information and Azure configuration. Sign in to your Windows Azure account via Windows Azure web portal.


Subscription ID

We will need the Windows Azure subscription ID to publish from LightSwitch. To find it, click “Hosted Services, Storage Accounts & CDN” tab on the left side of the portal.


Select “Hosted Services” on the side menu. Select the subscription node in the middle pane. You will find your Subscription ID on the right side of the portal.


Hosted Service

With the “Hosted Services” selected on the side menu, you will see a list of existing hosted services. A hosted service is the actual website that will be hosting your LightSwitch application. You will need a hosted service to publish from LightSwitch. To create a new hosted service, click “New Hosted Service.”


In the “Create a new Hosted Service” dialog, specify a service name and a unique URL prefix. The URL will be used to access your LightSwitch application once it has been deployed. Next, choose a region to host the service. I’ll pick “North Central US.” Select “Do not deploy” since we’re deploying from LightSwitch instead of this web portal.


You will see the newly created service in the list.


Storage Account

You will also need a storage account to publish from LightSwitch. The storage account is used to store your LightSwitch application as it is being uploaded to Windows Azure. Select “Storage Accounts” on the left menu to see a list of existing storage accounts. To create a new storage account, click the “New Storage Account” button.


In the “Create a New Storage Account” dialog, specify a unique URL name. I’ll choose “North Central US” again. Click Create.


The newly created storage now shows in the list.


Database Server

Next we need to make sure you have a database server set up. You only need to do this once per subscription. If you have not set up a database server, click Database in the left menu. Select your subscription account and click “Create” button.


Specify a region and click Next. Notice that I used the same “North Central US” region for hosted service, storage account, and database server. This is to ensure that my web role instance lives in the same region as the SQL Azure database to reduce latency on database calls and bandwidth charges.


Specify a name and password for the database administrator and click Next.


The next page of the wizard will set up firewall rules for your SQL Azure account. Check “Allow other Windows Azure services to access this server” to allow your LightSwitch application to connect to this database server.


You will also need to add a rule for your development machine to allow the LightSwitch Publish Wizard to update your database. Click Add to add a rule. In this example, I am going to allow all machines in my domain.


Click OK and then click Finish.

Once you have created a database server, select the database server node in the web portal. The Server name will be the Fully Qualified DNS Name on the right side. The administrator login will be listed on this page as well. You will need the server name and login information when you publish from LightSwitch.


Deploying a LightSwitch App

Now create a LightSwitch project with Forms authentication. I have a very simple LightSwitch application called “HelloWorld.” It has only one table and one screen. I’m ready to publish… TO THE CLOUD!

Right click on the project node in the Solution Explorer and select Publish.


Step 1: Client Configuration

The Publish Wizard now appears. It will guide us through several steps. Our first decision to make is to publish as a desktop or web application. LightSwitch supports publishing browser-based and desktop applications to the cloud. In this example, we will choose Web application and click Next to Step 2.


Step 2: Application Server Configuration

Since we want to host the application in Windows Azure, select Windows Azure option and click Next to Step 3.


Step 3: Connect to Windows Azure

In order to connect to Windows Azure, you need to provide your Windows Azure subscription ID and a management certificate. We already found the subscription ID in the Windows Azure web portal earlier. Go ahead and fill it in.


The management certificate is used to authorize your computer to update hosted services on Windows Azure. You can select an existing certificate from the dropdown menu. To create a new certificate, select “Create new self-signed certificate” from the dropdown menu.


Name the certificate and click OK.


The Windows Azure certificate store must contain a copy of the certificate. Therefore we need to upload the certificate we just created to Windows Azure. Click “Copy Path” button to copy the location of the certificate and go back to Windows Azure portal.


In the Windows Azure portal browser window, select “Management Certificates” to see a list of existing certificates. Since we want to add a new one, click “Add Certificate” button.


In the Add New Management Certificate dialog, click “Browse.”


Paste the location of the certificate in “File name” and click Open.


Click “Done” to add the certificate. You will see the newly added certificate in the list.


Back in LightSwitch, click Next in the Publish Wizard to Step 4.

Step 4: Azure Service Configuration

In this step, we need to specify the hosted service, storage account, and environment information for the deployment. We’ve already created the hosted service and storage account in the Windows Azure web portal earlier and you should see them in the dropdown menus. You can choose the environment to Staging or Production. In our example, we will keep it as Production. Click Next to Step 5.


Step 5: Security Settings

When deploying to Azure, LightSwitch requires HTTPS for secure connections to your application. This requires the use of an SSL certificate. The dropdown will list all SSL certificates that are already uploaded to Windows Azure. LightSwitch allows you to upload an existing SSL certificate (or one from a licensed vendor such as VeriSign). In our case, we’d like to test it with a self-signed certificate. Select “Create new self-signed certificate” in the dropdown menu. Please note that since it is self-signed, the published app may result in warnings from your browser.


Fill out the information in the dialog and click OK.


The self-signed certificate is now created and selected in the dropdown menu. Click Next to Step 6.


Step 6: Database Connection

We now need to specify the connection information to SQL Azure. LightSwitch requires two connection strings in the Publish Wizard: an administrator connection and a user connection. The administrator connection will only be used by the Publish Wizard to create or update your database. The user connection string will be used by your LightSwitch application to connect to the database. In the LightSwitch Publish Wizard, click the “…” button for the administrator connection.


In the Connection Properties dialog, enter the server name and login info. We’ve already gotten this information from the Windows Azure web portal earlier. Give the database a name. Click OK.


The User connection will be set to the same by default. For security purposes, create a separate username and password for the user connection string. Click “Create Database Login” button.


Specify a new user login and click Create. Then click Next to Step 7.


Step 7: Authentication

We have designed this application to use Forms authentication. Therefore we need to create an application admin account so you can log in to your app after publishing. When finished, click Next to Step 8.


Step 8: Specify a Client Application Certificate

You can choose to sign the Silverlight client application (Xap file) you are deploying. It will encrypt your client application. In our example, we will leave it unchecked. Click Next to Step 9.


Step 9: Summary

The last step shows you a summary of what you’re about to publish. FINALLY! Click Publish.


It will take about 5 minutes to publish to Windows Azure. You can see the status at the lower left corner of the LightSwitch IDE. Once it’s published, the Windows Azure web portal will launch.


In the Cloud

In the Windows Azure web portal, you can now see the application published under your hosted service. It takes about 10 to 15 minutes for the app to finish initializing. Once it is ready. Click on the DNS name link on the right side to check out the live website.


Since we used a self-sign SSL certificate (in Step 5), IE will warn about the security risk. Click “Continue to this website.” If you have used a licensed SSL certificate, you will not see the warnings.


The web application starts up showing you the log in screen. Type in the administrator credential you created in Step 7 and click “Log In” button.


Voila! We have a web application hosted in Windows Azure and SQL Azure with Forms authentication!



Starting with LightSwitch Beta 2, you now have the ability to publish your desktop and browser-based applications to Windows Azure and SQL Azure. I’ve detailed all the steps necessary to get started with Azure and deploy your first application. Once you have an Azure account and services set up, the republishing of the application is easy. Have fun building cloud-based applications with Visual Studio LightSwitch!