Deploying ASP.NET Core Applications from Bitbucket to Azure
Tags: azure, aspnet, git, deployment
Published: 2017-11-30 20:28:28

---
title: Deploying ASP.NET Core Applications from Bitbucket to Azure
published: true
cover_image: https://i2.wp.com/leruplund.dk/wp-content/uploads/2017/11/DSC_0547.jpg?fit=1008%2C675
description: Deployment of a website is boring and errorprone. Azure offers a very simple way to deploy websites directly from your code repository.  
tags: Azure, ASP.NET, Git, Deployment
canonical_url: http://leruplund.dk/2017/11/30/deploying-asp-net-core-applications-from-bitbucket-to-azure/

---


*This article originally appeared on my [personal blog](http://leruplund.dk/2017/11/30/deploying-asp-net-core-applications-from-bitbucket-to-azure/).*

<blockquote>
Give the most tedioust jobs to your laziest employee and they will automate it.

<cite>My boss</cite>
</blockquote>

That's right.  I am lazy.  I hate repetitive tasks.  And as a developer you probably feel the same way.

One of those repetitive tasks is deployment

There are numerous ways and frameworks to set up automated builds and deployments.  Some of them can do just about anything almost up to the point where they will make you coffee while you wait for your builds.

Recently while working on a small ASP.NET Core website I found out that Microsoft Azure has a very simple deployment tool for building and deploying from your favourite code repository to an Azure web application.  I was especially happy to find that it supports BitBucket even though it seems anything not-on-Github is not cool.

Well, I am too old to be cool and I like Bitbucket so bear with me.

## Setup
Setup is a breeze.  Got to the [new Azure portal](http://portal.azure.com) and create your new web application.

After the web app has been created, go to your web app and choose "Deployment Options".

<img src="http://leruplund.dk/wp-content/uploads/2017/11/azure-deployment-options.png" alt="azure-deployment-options" width="1076" height="793" class="alignnone size-full wp-image-767"/>

The next steps allow you to log in to your source code provider (i.e. Bitbucket) and choose project and branch (typically the master branch).  The beauty here is that Azure supports pulling code from all kinds of sources like Dropbox, Onedrive, Github, and of course Bitbucket.

<img src="http://leruplund.dk/wp-content/uploads/2017/11/azure-deployment-options-configure.png" alt="azure-deployment-options-configure" width="945" height="663" class="alignnone size-full wp-image-766"/>

After you save your settings, Azure will fetch your last commit and start building it.  You can se the progress by clicking "Deployment options" again.

<img src="http://leruplund.dk/wp-content/uploads/2017/11/azure-deployment-progress.png" alt="azure-deployment-progress" width="857" height="433" class="alignnone size-full wp-image-790"/>  

## Build Errors?
It looks like Microsoft has just recently upgraded the compiler but I have previously run into problems with building newer C# features such as inline declaration of variables like so.
 
```CSharp
var salaries = new Dictionary<string, decimal>()
{
    { "Jakob", 10000000000 },
    { "Some other guy", 42 },
};

// Inlining variable declaration
if (salaries.TryGetValue("Jakob", out var salary))
{
    // Do something with salary.
}
```
If you run into this problem, all you need to do is add the Nuget package [Microsoft.Net.Compilers](https://www.nuget.org/packages/Microsoft.Net.Compilers/) to your project.  This will make sure that your project is compiled with the latest C# compiler.

## Conclusion
This kind of deployment is extremely simple and easy, which is a good thing.  On the other hand it will not run any unit tests in your project and it will deploy straight to production without any testing or staging.  You might consider this solution for smaller, non-mission-critical sites.