Hopefully you already know that publishing your LightSwitch app or Cloud Business App to an Azure Web site is the quickest and easiest way to get your app published. You may not know, however, about some recent enhancements in Visual Studio that also make it easier to manage and interact with Azure Web Sites.
Create an Azure Web site from the Server Explorer
If you have deployed a LightSwitch app to an Azure Web site before, you know that you first need to log into the Azure Management Portal to create the web site. Now you can create an Azure Web site from the Server Explorer inside of Visual Studio.
Open the Server Explorer and expand the “Windows Azure” node :
Then, right-click on the “Web Sites” node and select “Create New Site” (note that you will be prompted to login with your Azure credentials if you hadn’t done so prior to this):
Next, fill out all the info in the “Create site on Windows Azure” window then hit the “Create” button:
That will run for a minute as it creates your web site and database (the database name will be whatever your web site name is with the suffix “_db”). Once it is finished you will see it show up in the Server Explorer. Right-click on it and you will see several options for the web site, allowing you to do such things as view the site in a browser, open it up in the Azure Management Portal or view the site’s settings.
You might be asking yourself “What about that "Attach Debugger" entry Dave?” We’ll get there in a later section. Don’t worry.
Removing stale files from your Azure Web Site
This next setting has been in for a while, but I don’t think we’ve ever called it out in a blog post, so I will take this opportunity to do so. I am going to go ahead and publish a simple LightSwitch app. While I go through the LightSwitch Publish Wizard to publish to my newly created Azure Web Site, notice the checkbox on the “Service Configuration” page of the wizard:
If you check this box, it will delete any file from the web site that is NOT part of the deployed LightSwitch app. For example, the hostingstart.html page that says “Your web site has been successfully created", you don’t need that after you publish your app. Another prime example of when you would want to use this is if you upgrade a LightSwitch Visual Studio 2012 project to a 2013 project and want to deploy to the same web site. The directory structure of the deployed app changed between these releases, so if you don’t check the box in this case, you will have a bunch of stale files left and your app won’t work.
You need to be careful with this box though, as it will also delete files that you pushed to the site through some other means than the Publish Wizard.
View and Update files on the web site from Server Explorer
Another great feature of the Windows Azure\Web Sites node is the ability to view the files that are deployed to the web site. To do this, expand the target web site and then the “Files” node:
If you double-click one of the files, it will download a copy and open it up in the Visual Studio editor. For instance, you could open up the web.config and enable LightSwitch tracing. When you save the file you will be prompted:
If you click the “Save Changes” button, the file will be uploaded to your Azure Web Site.
Debug a running Azure Web site
So this is all fine, but now we get to the real gem. If you right-click on your web site in Server Explorer, you can select “Attach Debugger”:
You can debug your running Azure web site! To demonstrate, I created an Inserting handler for my LightSwitch app, deployed and performed Attach Debugger and put a breakpoint in my handler method. When I insert a record, I hit my breakpoint:
To prove that we are in Azure, I have printed out the AbsoluteUri of the current request. Note that I published a Debug build of my app, but it works with Release as well.
This is a very powerful ability as often there are problems with an app that don’t occur until the app is published. If your LightSwitch app isn’t working when published to an on-premises IIS server, publishing to a new Azure Web Site is a quick and easy way to determine whether it is the app’s problem or a problem with the IIS server configuration.
Hopefully, you will find these enhancements beneficial for creating, managing and debugging your Azure Web Sites.
-Dave Kidder, Senior SDET, Cloud Business Apps Team
Dave is a Senior SDET (Software Development Engineer in Test) on the Visual Studio team focused on LightSwitch as well as tooling for Office and Azure. He started on this team in September of 2012, prior to that he was testing different aspects of ERP platform software since May of 1999, working on the Dynamics AX Client from 2007 up to the transition to Visual Studio.
Dave is a die-hard Minnesota Vikings fan. He was recently “knighted” into Thee Viking World Order.