How to deploy Umbraco 7 to an Azure Website using Visual Studio Online

So last week I thought I would quickly knock up an Umbraco 7 website and host it on Windows Azure so I can hack about with it while I’m at the Umbraco Codegarden conference this week. It’s pretty simple to set up an Azure Website with Visual Studio Online and I thought I would have the site up in probably an hour or so.

I was wrong. So wrong. I spent three ‘fun’ evenings pulling my hair out with frustration because I couldn’t get the deployment process to work! I like my hair. It’s going a bit too grey a bit too soon, and the back bits are a bit too curly, but I prefer my hair to no hair. So if you also like your hair and would prefer to keep it as it is, then read my How To below:

First you need to set up your Visual Studio Online repo and your Azure Website. See this post that walks through how to do that. Next create an empty MVC project in Visual Studio (I’m using VS2013 for these screenshots, but all the steps are the same in VS2012):

deploy-umbraco-on-azure-websites-using-visual-studio-online-1

Remember to add your project to Visual Studio Online as you create it (probably should have told you that before that last step – oops…).

Next, install the latest Umbraco 7 components into your project (I use the NuGet Package Manager Console for this, as it’s faster than browsing through the NuGet gallery and typing stuff into the console makes me feel like a proper developer…):

deploy-umbraco-on-azure-websites-using-visual-studio-online-2

You will be prompted to overwrite your web.config and Global.asax files. Choose ‘yes’ to both of these questions:

deploy-umbraco-on-azure-websites-using-visual-studio-online-3

Now here’s the bits they don’t tell you in the textbooks – since you’re going to be deploying this project through Visual Studio Online, you need to include all the additional Umbraco files and folders in your Visual Studio project. So click on the ‘show all files’ icon at the top of the Project Explorer:

deploy-umbraco-on-azure-websites-using-visual-studio-online-4

You then need to include the following folders (right click on the folder and choose ‘Include in Project’):

deploy-umbraco-on-azure-websites-using-visual-studio-online-5

One final gotcha for the code bit – when Visual Studio Online tries to build your project it will try and transform any web.config files in there (or at least it did for me!) so you need to change the build action on the web.config file within your XSLT folder, from ‘Content’ to ‘None’:

deploy-umbraco-on-azure-websites-using-visual-studio-online-6

That’s the code all ready to go. The next bit is the database.

UPDATE: so I just realised that since writing this blog post I actually worked out that you can just point your Umbraco install directly at a new SQL Azure database, and it will create your database there rather than having to go through the faff below. I’ll blog on that when I get a chance. The below steps are still useful if you want to create a local dev DB and then copy that up to SQL Azure for staging/production…

NOTE: the database deployment to Azure will only work if you’re using Sql Server Management Studio 2012. I know this from bitter experience (more hair lost) trying various ways of getting my database up to Azure using SSMS 2008…

Another gotcha with Visual Studio Online is that it won’t build the project unless there is a valid database connection string in your web.config file. So at this point you need to create a local SQL Server database, run your Umbraco project install process from the browser (hit F5 and Visual Studio will build and launch your Umbraco website and you should be prompted to set up your user profile and database connection string).

I’m going to assume that you know how to do this bit and that there’s no need for me to document it. Lazy is not the right word, but it will do for now.

Now you have a local database and your web.config connection is set up, you can check your project into Visual Studio Online which will then build and deploy it to the Azure Website you set up earlier.

The next stage is to copy the database up to Azure. As I said earlier you will need SSMS2012 to do this bit. Sorry I don’t make the rules…

First off you need to export your database as a data-tier application. Right click on your databases and choose Tasks > Export Data-tier Application:

deploy-umbraco-on-azure-websites-using-visual-studio-online-7

Choose the ‘save to local disk’ option:

deploy-umbraco-on-azure-websites-using-visual-studio-online-8

Click finish and let the magic happen. You should see the following screen if everything has worked as it should:

deploy-umbraco-on-azure-websites-using-visual-studio-online-9

The next step is to deploy your database to Azure. Connect to your Azure SQL server (again you need to do this through SSMS2012) , right click on the Database folder and choose ‘Import Data-tier Application’:

deploy-umbraco-on-azure-websites-using-visual-studio-online-10

Choose the .bacpac file you just created for the source of the import:

deploy-umbraco-on-azure-websites-using-visual-studio-online-11

On the next screen you have to connect again to your Azure SQL Server (not sure why) and also give your new Azure database a name (make sure it’s the same as your local database, so your web.config connection strings still work):

deploy-umbraco-on-azure-websites-using-visual-studio-online-12

Finally, hit the ‘finish’ button, cross your fingers and hold your breath. If the planets are aligned and it’s a leap year, your database will magically be deployed to Azure and you will see this screen:

deploy-umbraco-on-azure-websites-using-visual-studio-online-13

So that’s the hard bit done with, and you now have a fully functioning Umbraco website hosted on Azure, and being continuously deployed through Visual Studio Online. Next you just have to build the website, but I’m assuming you already know how to do that? 🙂

Tagged with: , , ,