Deploying the ASP.NET KRuntime Beta1 to Azure Websites

3 minute read

Unless you lived under a rock during the last few days, you should know by now that Microsoft shipped a Preview of VS2015 with support for ASP.NET vNext. Such announcements traditionally result in developers screaming "yeay, new bits!", late night coding and unlocking Untappd badges with each commit.

Working on a little side project, I wanted to explore ASP.NET vNext beta1 on Azure Websites. I quickly learned that Azure Websites currently only provides alpha-support. On top of that, the kvm command switches have changed (esp. kvm install), so there's no straightforward kvm upgrade that will do the trick. This post shows you how I got an ASP.NET MVC6 beta1 application working on Azure Websites using x64 CoreCLR (Note: my Azure Website is configured to run x64 on the Basic tier). Feel free to use whatever version you want, YMMV!

Instructing Kudu to run a custom deployment

First things first: for this to work, you'll need to take advantage of Kudu by connecting your Git repository to Azure Websites. Let me Google that for you with Bing! Kudu will generate deployment scripts under the hood and deploy your website when pushing changes to your source repository. However, deployment will fail for an ASP.NET vNext beta1 application. To fix this, you'll need to customize the deployment scripts. This is the easiest part: simply add a .deployment file and an empty deploy.cmd to your source repository (don't bother downloading the script that Kudu uses out-of-the-box, it's flawed at the moment). The .deployment file looks like this:

[config]
command = deploy.cmd

Before we take a look at the deploy.cmd, we'll first have to setup the K Version Manager (KVM).

Setting up KVM

As the interactions with the Azure Websites environment are constrained due to security, we can't just install kvm by following the Getting Started guide (not during deployment, and not from within site extensions). Installation will fail as the kvm.ps1 script being used under the hood contains lots of Write-Host statements that will cause exceptions. In fact, when you try this, the first Write-Host statement encountered is the one that should log an exception to the console, so it just doesn't work.

This leaves only one option: having a kvm.cmd in the repository root calling into a customized kvm.ps1, and call it from a custom deploy.cmd. Let's skip the download process and adapt the PowerShell script to our needs and check-it into source control. The following links point to their gists:

The kvm.cmd file is unmodified and matches the one from the ASP.NET GitHub repository. The kvm.ps1 file I created is also based on the v1.0.0-beta1 tag and has the following modifications:

  • It uses a WriteLine function that simply echo's the text into the console host, and all calls to Write-Host are replaced by calls to this WriteLine function.
  • The ZIP unpack logic in the script (which uses PowerShell's built-in unzip functionality) is replaced by calling into .NET's ZipFile::ExtractToDirectory method. The original extract logic didn't work and silently failed.

Customizing the deployment

Now we have almost everything in place except for the real deployment instructions. The deploy.cmd file is the one that our .deployment file points to so let's take a look at how we can leverage our custom KVM.

I didn't create this from scratch though. Remember, I started from the deployment scripts that got generated by Kudu. In a nutshell, here's what the script does:

  1. Check pre-requisites and configure environment variables
  2. Install KRE (by calling into the custom kvm.ps1 file)
  3. Run KPM restore
  4. Run KPM pack
  5. Run KuduSync
  6. First-hit of the web site (warm-up call)

The full deploy.cmd file can be found here: deploy.cmd. You can easily customize the script to your needs by changing the variables set in lines 82-85.

SET KRE VERSION=1.0.0-beta1
SET KRE_ARCH=amd64
SET KRE_CLR=CoreCLR
SET ProjectJsonFile=My.Awesome.DemoApp\project.json

Wrapping up

I'm sure built-in support is coming, but if you want to have a play with it on Azure Websites today, this might just do the trick for you. I'd like to thank David Ebbo for pointing me towards this tweet, referencing Louis DeJardin's GitHub repository: it helped me to get this working :)

Link to all gists used in this post: https://gist.github.com/xavierdecoster/c56561312891eb788b8d

Leave a Comment