Easily Deploy Your LightSwitch Apps to Azure Websites in Minutes

Easily Deploy Your LightSwitch Apps to Azure Websites in Minutes

Rate This
  • Comments 15

As part of my demo preps for all the conferences I’ve spoken at recently I’ve been deploying my LightSwitch apps to Azure websites and I can honestly say that it is by far the easiest way to get a LightSwitch application up and running. Of course you can always manually set up your own server, database and network if you want a purely internal business app like I’ve showed in these deployment posts. However, it’s always hard to troubleshoot what goes wrong when a deployment goes bad because everyone’s environment is a little bit different. The great thing about Azure websites is the environment is hassle-free and already ready for you to deploy your LightSwitch applications.

In this post I’ll detail step-by-step how to deploy a LightSwitch application to Azure websites. But first, you may be wondering what the heck is an Azure website and what’s the difference between that and a cloud service? LightSwitch applications can be deployed to both through the Publishing Wizard, but why would you choose one over the other?

Azure Cloud Services provide reserved, infinitely scalable, n-tier options running on a Platform as a Service (Paas). Azure Websites are for quick and easy web application and service deployments. You can start for free and scale as you go. So if you do not need all the other advanced services like Business Analytics, Service Bus, or Identity that the Azure cloud services provide and you only have a LightSwitch application to deploy, then an Azure website is the right choice.

If you’re interested in deploying to cloud services see Andrew & Brian’s post: Publishing LightSwitch Apps to Azure with Visual Studio 2012

Step 1: Build Your App

Of course we’re going to need an application to deploy ;-) so in this post I’ll use the Contoso Construction sample that is available on the Samples Gallery. This is a good advanced sample that uses external data sources as well as some extensions so it’s a good example of a typical LightSwitch application out there in the real world.

I want to host the application as a desktop client with the services and SQL database in Azure. Azure websites are perfect for this. Since the desktop client of a LightSwitch application is just a Silverlight application it’s the same type of hosting; the XAP file sits on the web server and when a user navigates to the URL, it is automatically installed into their Windows start menu just like any other program. The reason why we need to deploy this as a desktop app is because we do a lot of Office automation in this sample using the Office Integration Pack extension and so we need to run as a full trust Windows application. Silverlight gives us the ease of web deployment with the benefits of running full trust out-of-browser.

image

Step 2: Sign Up for Azure Websites

Before you can publish to the Azure website you need to sign up. Once you sign up and create a subscription you will have access to your own portal. From the portal you can then manage all your cloud services, websites and databases all in one place.

Step 3: Create a New Website & Database

Once you get to your portal, select the WEB SITES tab and click NEW.

image

All LightSwitch applications need a SQL database so make sure you create a corresponding database for your new website by selecting that option.

image

Next, specify the name and location of your website. Make sure you pick a location near most of your users.

image

Next create your database server (if this isn’t your first time, you can select an existing server as well). Make sure the database server is in the same region as your website for the best performance.

image

Click OK and your website and database will be set up. Lastly, in order to publish the database from Visual Studio, you will need to make sure the database server trusts your computer by adding a management certificate. The easiest way to do this is to select the database in the portal and click MANAGE at the bottom. This will prompt you to create the certificate automatically if you need one.

image

Step 4: Publish

In Visual Studio, make sure you’re configuration is set to Release and then right click on your project and select Publish from the menu. You can also go to the Project Properties - Application Type section and click the Publish button to launch the Publish Wizard. (If you’re configuration isn’t set to Release then the Publish Wizard will give you a warning.)

image

The first question you’re asked is what type of application you want to publish. In our case, we want to select “Desktop”. Notice however that you can also deploy your application as a browser application as well as just the services (middle-tier). Deploying just the services makes sense if you have only external OData clients accessing your service. The LightSwitch OData services are always published, but you can choose whether the LightSwitch client is published or not via this dialog.

image

Next you need to specify where to deploy the application. You can deploy a LightSwitch application in multiple ways. You can deploy it as a simple two-tier (traditional client-db server) application, or you can deploy as a scalable n-tier architecture in which case you can select to deploy to an IIS web server or Windows Azure. In our case we will select Windows Azure.

image

Next you will need to specify your Azure subscription information. Simply click the link to sign in to download your credentials. Then click Import to load them into the LightSwitch Publish Wizard. Once you do that, your settings will be loaded for the subscription you set up and automatically selected. (My Azure subscription name is “Demo Projects”).

image

Next we need to specify the service type. Here is where we can choose to deploy to an Azure cloud service or an Azure website. Select Website and click next.

image

Next we need to specify the Website we want to publish to. This will be the same website you specified in the portal.

image

Next we need to specify security settings which has multiple parts. First, if you have specified to use Authentication in your application you will need to specify the application administrator who will have first access to the app. This user is responsible for adding Users to Roles in order to set up access permissions. (For more info on LightSwitch Access control see: Securing Access to LightSwitch Applications). For the Contoso Construction application, it uses Forms Authentication so I’ll need to specify the App Administrator here.

image

You’ll notice two other tabs on the Security Settings section of the wizard. The HTTPS tab specifies if traffic should be sent over a secure channel SSL. It is highly recommended that you set up secure communication between your LightSwitch data services on your middle-tier and any client accessing them. Otherwise malicious users could sniff network traffic and see the data that you were transferring from the client to the services. Fortunately, Azure websites are set up to handle HTTPS traffic so select that option.

image

On the last tab of Security Settings, you specify a digital signature for your client desktop application. This is only necessary if:

  • You are publishing a desktop application
  • You want to be able to publish updates automatically to desktop users

If you do not specify a digital signature on a desktop app then when you update the application then users will have to uninstall and reinstall the app before they can use it. Specifying a digital signature is a good idea in general anyways so that users see a trust prompt when installing. You should use a digital signature from a trusted certificate authority like VeriSign. However you can also create internal certificates and then install them into the trusted root cert store on the client machines (Internet Options – Certificates). This is a good option for testing or for internal applications. For this example, I have already created a test certificate and installed it into my trusted root store so I can select that here.

image

Next we need to verify the connections to our database and any external data sources (if any). When we created a corresponding database for our Website in the portal, the database information is picked up in the Publish wizard. Make sure you check “Publish database schema” so that the database is created.

image

The Attached Data Sources tab will appear if you are using any external data sources, like OData Services or other external databases. You can verify those connections here. The Consotso Construction app uses a OData service from the Windows Azure Marketplace which contains free (as well as pay) data sets that you can use to enhance your LightSwitch applications.

image

Finally, a summary page is displayed. Click Finish and your app will be deployed to Azure Websites in about 2 to 3 minutes.

image

You can watch the deployment progress in the Output window in Visual Studio. It should be pretty quick, I’ve never seen it take longer than 2 minutes for my apps. Once complete the portal will open and you can hit the URL you created to launch your application which you can find to the right of the Website entry in the portal.

UPDATE: If you are using Visual Studio 2012 Update 2 or higher and have upgraded your LightSwitch project to V3 or higher (or added an HTML Client project), then you will need to navigate to the corresponding client subfolder. i.e. myazurewebsite.net/Client for desktop, myazurewebsite.net/HTMLClient for HTML.

image

With a desktop application it will prompt users to install the application like so.

image

Once you install the app it will launch. Users can then re-launch it from the start menu at any time. An icon is also placed on the desktop. You can uninstall it via Add/Remove Programs just like any other application. Additionally if you make changes and then republish the application to Azure, next time users launch the application it will be automatically updated and users will be directed to simply reopen it.

Of course, you can also host in-browser applications in Azure exactly the same way. In that case, users will use their favorite browser to navigate to the URL when they want to use the application. Also keep in mind that in-browser apps do not run in full trust so you can’t do COM automation like we are in this sample.

I hope this shows you how easy it is to get started with Azure websites to host your LightSwitch applications. LightSwitch makes it super fast and simple to develop business applications and now with Azure websites they can be deployed even faster. For more information see the Visual Studio LightSwitch Developer Center and the Windows Azure Websites offering.

Enjoy!

Leave a Comment
  • Please add 1 and 5 and type the answer here:
  • Post
  • Thank you very much, Massi!!!

  • Great Article, thansk so much.

    I'm deploying the Lightswithc application to Azure for the first time.

    My SQL database has production database how can I deploy the data with database?

    Thanks,

    Rachida

  • Good question by Rachida. Also, how does one cope with schema migrations using lightswitch?

  • JeroenHa , I foud this video tutorial very useful for our question:

    This walkthrough demonstrates how to move data from an on-premises Microsoft SQL Server data store to SQL Azure

    www.youtube.com/watch

    Good luck

  • Great tutorial Beth, keep them coming! Had my app up & running in minutes indeed!

    One extra hint: once you get to your already existing Azure portal, it looks nothing like the screenshots you posted... At the bottom left however you'll find a link to take you to the "preview portal", click it, enjoy the rest of the tutorial :-)

  • Great tutorial,

    What about deploying an MVC web app using same db on the side? The scenario here is MVC business app and lightswitch admin interface.

    Thanks,

    John

  • Excellent!!! This has been extremely helpful to me. Its just what I needed.

    1000 Thanks,

    Jim

  • HI

    Great article but do you have an update for VStudio 2013? It says to deploy to azure you need .net sdk but on Microsoft websites it says the sdk not out yet??

    HELP

  • @Mier R -- that's correct, Azure publishing is not available yet in the preview. See our release notes here: social.msdn.microsoft.com/.../lightswitch-in-visual-studio-2013-preview-and-lightswitch-in-visual-studio-2012-update-3-release

    We will update this when the SDK is released.

    Thanks,

    -Beth

  • @Mier R -- Good news! They just released the Azure 2.1 SDK so you should be able to publish your LightSwitch apps now through Visual Studio 2013 preview.

  • Hi Beth,

    Very useful article!

    One thing I was curious about though, is there a way that we can integrate apps that are published to Azure websites with Azure Active Directory at all?

    Would be really awesome if you could!

    Andrew.

  • Great article.  I've followed the directions to the T.  However, I still get the message You do not have permission to view this directory or page.  Default.htm is at the top of my default page types in Azure.  Connection strings have been tested.  I've turned on FREB but am unsure how to diagnose this further?

  • Hi Sid,

    If you are using Visual Studio 2012 Update 2 or higher and have upgraded your LightSwitch project to V3 or higher (or added an HTML Client project), then you will need to navigate to the corresponding client subfolder. i.e. myazurewebsite.net/Client for desktop, myazurewebsite.net/HTMLClient for HTML.

    I updated the article to reflect the new behavior in the recent editions of VS. Thanks!

  • Beth,

    There is an issue with the method mentioned in this article to create and Publish the project when you get to the "Service Configuration" Tab.

    Posted this message on the MSDN Forums for LightSwitch:

    Microsoft LightSwitch Deployment:: "<cannot connect to windows azure>" using "visual studio 2012"

    See this link:

    social.msdn.microsoft.com/.../microsoft-lightswitch-deployment-cannot-connect-to-windows-azure-using-visual-studio-2012

    Dave Kidder posted this as the solution:

    ---

    This is a known issue due to a service interface change by Azure Websites.  You can publish to Azure Web Sites using the IIS path of the publish wizard by following the steps in this blog post:

    blogs.msdn.com/.../publish-lightswitch-2013-preview-applications-to-windows-azure-web-sites-without-the-azure-sdk.aspx

    (Disregard that it refers to the 2013 preview, this will work for VS 2012)

    David Kidder | Senior SDET | Microsoft | LightSwitch

    ---

    Thank you Beth for your excellent articles and Videos for Microsoft LightSwitch. Glad to see that someone at Microsoft actually uses Visual Basic on Projects.

    BillNew

  • Hey beth,

    Any idea if they are planning to provide the possibility to publish lightswitch applications by use of azure websites, getting their sources from an external repository ? When trying to deploy a website, I'm getting the "Microsoft.LightSwitch.Build.Tasks.targets" was not found" build error.

    Handling .NET Web Application deployment.

    All packages listed in packages.config are already installed.

    D:\home\site\repository\myProject\myProjectlightswitch\myProjectlightswitch.Server\myProject.lightswitch.Server.csproj(230,3): error MSB4019: The imported project "D:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\LightSwitch\v4.5\Microsoft.LightSwitch.Build.Tasks.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

    Failed exitCode=1, command="D:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"

Page 1 of 1 (15 items)