The easiest way to create modern business applications for the Cloud and Office 365
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!
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.
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.
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.
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.
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.
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.
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.
Since we want to host the application in Windows Azure, select Windows Azure option and click Next to Step 3.
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.
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.
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.
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.
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.
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.
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 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!
First off I want to say that I really want to get into and understand LightSwitch. The Azure option seems quite interesting but I have a question and that is once I start down the path of using LS and Azure am I fully committed at that time? Lets say I get a bad experience with Azure (e.g. I just don't want to pay the price) but I still want to recoup my investment in LS. How easy is it to take the non-azure portion of my LS app and point it to Sql Express? Obviously the ideal situation is to invest you time by having a rich model that doesn't care about persistence.
Thanks for the great work,
Deploying to Azure is just one option. You can also deploy a LightSwitch application as a two tier or three tier application running against SQL or SQL Express. If you take a look at the screen shots in Step 1 and 2 above you can see those options.
So IOW, no you are not required to deploy your apps to Azure. You could deploy them anywhere. We'll be writing up more walkthroughs this week on how to set up your own environment to host LightSwitch applications. Stay tuned.
I'm having a nightmare deploying to localhost on my Windows 7 dev box or Windows Web Server 2008 R2. I managed this with Beta 1 with minimal problems but something strange is happening with Beta 2. Blank Application screen - No Menus. Publishes OK using wizard either via http://localhost running VS in Admin mode on Windows 7 or via MSDEPLOY onto our local Web Server. Database Schema (still no data!!! - but that's for another thread) and Web App created OK allegedly. I await your guidance hopefully soon. So I'm staying tuned......
I'm working on a revampped Beta 2 deployment guide right now (like now now! ;-)). I just sent it off to a couple people to review so I hope to have it posted very soon. Stay tuned!
This is perfect - just what I was looking for - many thanks.
Great directions, Andy.
It worked just fine first time through.
Hi, I am having some issues publishing my LS app to Azure. I have configured my Azure account as described above, and I am able to complete the steps of the 'Publish to Azure' wizard without any issues.
I get through the publish wizard okay, but when it actually attempts to publish to Azure it is running into an error:
Error 67 Unable to find node with ServiceDefinition name 'Amex.RetailHub.CMS' and WebRole name 'LightSwitchWebRole' in file 'C:\svn\retail-hub-cms\Amex.RetailHub.CMS\Bin\Debug\ServiceConfiguration.cscfg'
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\LightSwitch\v1.0\Microsoft.LightSwitch.targets
It appears as if Lightswitch added a bunch of stuff to the ServiceConfiguration.cscfg file that are causing validation errors. In fact, this one Error is accompanied by another odd 60+ "warnings" about the configuration file containing invalid elements and whatnot.
If anyone is familiar with LightSwitch configuration files or has an idea as to what I've done wrong, any input would be greatly appreciated.
I have created a post on the LightSwitch Beta 2 forums: social.msdn.microsoft.com/.../e2b47d65-2c92-44d8-9ac4-a707212d5999
I followed every steps you have included here. But i got this problem.. Any thoughts?
Unable to find node with ServiceDefinition name 'Ib.LightSwitch' and WebRole name 'LightSwitchWebRole' in file 'C:\Personal\Project\OnePiece.Ib\src\app\Ib.LightSwitch\Bin\Debug\ServiceConfiguration.cscfg' C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\LightSwitch\v1.0\Microsoft.LightSwitch.targets Ib.LightSwitch
@Rommel - Check out this answered forum post to see if it respolves your issue:
Great! I was able to host my application on Azure. The deployment process was faster than localhost :)
And now I want to deploy multiple applications, so I am assuming that the storage service will be same and I would create new host service?
What all changes are required to host second application?
@Sawan - yes, you just need to create a 2nd hosted service.
Thanks for the walkthrough, i managed to get it working.
But now i want to deploy it a an Windows Authentication application. And I'm trying to set up some things in ACS appfabric, but i cannot get it to start working. Can anyone of the team help me out?
Is it even possible?
If you’d like to use Windows Auth, you need to join your Azure Service to your company’s domain (using Azure Connect). To get Azure Connect working with Domain Access, you need to join your Azure Role to a domain controller.
Thanks for posting such a descriptive post. It helps a lot. Thank you very much.