Build .NET 4.5 on Linux in 5 minutes

Hudson Mendes

Although .NET 4.5 solutions (.sln) cannot use the convenient dotnet CLI (from .NET Core 1.1), you still can make it. This article will get you building .NET 4.5 Solutions within 5 minutes and prove that it's not just possible, it's easy!


This article WILL NOT teach you how to wrap your application in a Docker Container. The procedure for that is different.

We use Docker here purely to have a bash running on top of your Windows without the need of a VM (at least not a VM that you will have to lift), which is therefore a lot faster (and easier, I gotta say).

The sole objective of this article is to teach you How To Build .NET 4.5 Applications in a Linux Environment using Mono and XBuild.

If you are already on a Linux Environment?

In case you are running on a Windows Machine, run through the first 2 steps to get a bash machine where you can test this procedure.

Otherwise, if you are already on MacOS or Linux, you can skip steps (1) and (2) and go straight to the step (3).

Developing on Windows, testing on Linux? Don't do a VM, use a docker container — it's much faster

I covered How Docker Works in the article Docker + Java Microservices: Choosing the Base Image for Java 8/9 Microservices (on Linux and Windows).

1. Installing Docker for Windows

You can get the official latest Docker for Windows. It has good support for both Linux Containers (running on top of Hyper-V) and Windows Containers (which we are not going to use here).

2. Start an Interactive Docker Bash

You can very easily and quickly have a fully operational Linux Bash right inside your Windows Command Prompt by running attached to a ubuntu docker container, functioning seamlessly.

Open your Docker Shell / Docker Command Prompt, installed alongside your Docker for Windows, and run the following command:

docker run -t -i ubuntu /bin/bash

You will see that your prompt is now a bash superuser-styled prompt (with the #). Welcome to your Ubuntu Linux.

And yes, it did only take you 5 seconds to put it up, after the images were downloaded. Docker Magic!

Building the .NET 4.5 Application from your Ubuntu Linux Bash

3. Update your Aptitude Package Cache

The Ubuntu Docker image doesn't come with any cache. So first thing you gotta do is to update it.

apt-get update

4. Install Nuget, Mono-devell and Mono-XBuild

These are the things you will need to build in Linux.

apt-get install -y nuget mono-devel mono-xbuild

5. Update your Nuget, you will need the most recent version

Some packages just can't be downloaded by older version of nuget. Here, for example, I had to update mine from 2.8 to 3.5. You do that by running the following command:

nuget update -self

6. Clone your git repository

The command bellow clones a sample repository that will be used for the purpose of this exercise:

apt-get install -y gitmkdir /srccd /srcgit clone benchmark_dotnet_mono_build_webapi

7. Restore your Nuget Packages

That will be very important for the build to succeed, in most of cases.

nuget restore

7. Build


xbuild AndrewJenkins.sln

Run the command below to notice that you now have a .exe built in the your app's bin folder.

ls ApiPeople/bin/Debug/*.exe

Once you got that, wrapping it up in a Docker Container should be a no-brainer.

Hope you liked it!

Hudson Mendes

Written by

Lean Entrepreneur, 16y+ Software Engineer, .NET (& .NETCore) and Java (J2EE, Spring) Specialist, Ruby (and Rails) lover, Open-Source Enthusiast and Contributor

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade