}

WATK in F#, Part 1: Building and Publishing Windows Azure Web Sites

WATK in F#, Part 1: Building and Publishing Windows Azure Web Sites

Here begins a series of posts showing how I used F# to write some of the Hands-On Labs in the Windows Azure Training Kit (WATK). WATK is a good way to learn the basics of Windows Azure development, but all the labs and samples are in C#. I want to show what it takes to write the HOLs in F# instead.

UPDATE: The code for the first three posts in this series is now on GitHub.

For this series I used the April 2013 version of WATK, the April 2013 release of the Azure SDK, and Visual Studio 2012 Premium.

Let's jump into the first HOL, entitled Building and Publishing ASP.NET Applications with Windows Azure Web Sites and Visual Studio 2012 (in the WATK folder under Labs\ASPNETAzureWebSitesVS2012). In this lab we create an ASP.NET MVC project in Visual Studio and publish it to an Azure web site two different ways -- first with Visual Studio publishing, then with a git repository. The lab demonstrates how easy it is to publish C# MVC projects to Azure web sites (as opposed to Azure web roles, which I'll cover in a future post). Let's see how easy it is to do with F#.

The first thing the lab has us do is create a new MVC 4 project in Visual Studio. The lab gives instructions for doing this in C#, but we will use Daniel Mohl's excellent F# / C# MVC template instead. We go to File - New Project and choose the template from Visual Studio's online gallery.

 

Choose F# / C# MVC Template

 

This version of the template offers us three types of project. We will choose Single Page App with Razor and Backbone.js. For this lab we'll omit the Tests project.

 

Choose Single Page App

 

The template creates a C# web project and an F# library project. The C# project contains no .NET code, but instead contains our views, scripts, stylesheets, configs and other MVC plumbing. All our .NET code, including models and controllers,  will be in the F# library project.

 

The template creates a single model class named Contact and two controllers, HomeController and a ContactsController.  Thus we don't need to create any new models or controllers to do the WATK lab. We can run the solution now from Visual Studio.

 

Run the App in Visual Studio

 

We're now ready to publish our MVC application to an Azure web site. First we log on to our Azure dashboard and create an empty web site, following the instructions in Exercise 1, Task 1 of the lab.

 

Create Azure Web Site

 

 

We'll postpone setting up a database for now, so we skip Exercise 1, Task 2 and go to Task 3. We right click on the C# project and select Publish. In the dialog we import need to import the publishing profile for the Azure web site we just created. We can do that either by following the lab instructions and download a publish profile file, or we can set up Visual Studio to import the profile directly from Azure; instructions for the latter procedure are on Scott Guthrie's blog.

 

Import Publish Profile

 

 

Ready to Publish

 

 

Since we haven't set up a database yet, we can leave the Settings pane alone for now. But we can test the deployment in the Preview pane, and if it succeeds, we click Publish. In a minute or two our F#/C# MVC 4 site is published to Azure!

 

So we've seen that the process of publishing an F# / C# MVC 4 project to Azure with Visual Studio is pretty much identical to the C# - only procedure described in the lab. In the next post, we'll look at how well we can publish the F# / C# MVC project using git.