Deploy ASP.NET 5 to an Azure Web App using Visual Studio Online

Posted on Saturday, September 5, 2015

When I was building this website, I wanted it to automatically deploy from VSO to my Azure Web App.
Since this website has been build with ASP.NET 5 (currently using beta 5 8) i couldn't just simply use the default stuff in VSO.

I found this great article by the VS ALM guys that discribe how to do that.

Unfortunatly when I followed the steps in that post I encountered some additional errors.
First was that my site has a custom domainname and that messed up the Powershell bit that grabs the deployUrl: $msdeployurl = $website.EnabledHostNames[1]
To get it working I had to explicitly tell the script to use the actual Kudu url.

After changing this, I was able to automatically deploy my website from VSO to Azure Web App.

Update for Beta 8

Currently (10/26/2015) the VSO hosted build controllers have not yet been updated for Beta 8. This means the default MsBuild Build step can not build a Beta 8 project.
Luckily dnu build and dnu publish can be used to build a solution in a PowerShell step.
To do this, I added the following PowerShell script DnuBuild.ps1 to my solution.

param($projectName, $buildConfiguration, $packOutput)

# load up the global.json so we can find the DNX version
$globalJson = Get-Content -Path $PSScriptRoot\global.json -Raw -ErrorAction Ignore | ConvertFrom-Json -ErrorAction Ignore

    $dnxVersion = $globalJson.sdk.version
    Write-Warning "Unable to locate global.json to determine using 'latest'"
    $dnxVersion = "latest"

# install DNX
# only installs the default (x86, clr) runtime of the framework.
# If you need additional architectures or runtimes you should add additional calls
# ex: & $env:USERPROFILE\.dnx\bin\dnvm install $dnxVersion -r coreclr
& $env:USERPROFILE\.dnx\bin\dnvm install $dnxVersion -Persistent

$dnxRuntimePath = "$($env:USERPROFILE)\.dnx\runtimes\dnx-clr-win-x86.$dnxVersion"

& dnu build $PSScriptRoot\src\$projectName\project.json --configuration "$buildConfiguration" 2>1
& dnu publish $PSScriptRoot\src\$projectName\project.json --configuration "$buildConfiguration" --runtime "$dnxRuntimePath" --out "$packOutput" 2>1

Add a PowerShell step using this script and Script arguments: -projectName {Your ProjectName} -buildConfiguration $(BuildConfiguration) -packOutput $(Build.SourcesDirectory)\Pub.
Do note the ProjectName argument, since the script is in my root solution folder, I need the ProjectName to get the project.json filepath.
Verify the PackOutput argument of the DnuBuild step matches the PackOutput argument of the PublishAspNet5Website step.
The MsBuild step can now be disabled (or removed) and a new build can be queued.

Since Beta 8 the following part is redundant
However, when I tried to update the website with some new bits, I got an error "Web Deploy cannot modify the file 'AspNet.Loader.dll' on the destination because it is locked by an external process.".

The reason for this is obviously that the AspNet.Loader.dll was still being used because my website was still up.
To solve this, I decided to modify the publish script to stop and restart my website during a deployment.
This of course means that my site is down during a deployment but I can live with that, at least for now.

Disclaimer: Any views or opinions expressed on this blog are my own personal ones and do not represent my employer in any way.