Building .Net Core On Travis CI

Written by Khalid Abuhakmeh

.NET Core is a cross-platform runtime, and if you play your developer cards right, you can take advantage of running your application on Windows, macOS, and Linux. We enjoy writing many open source projects. Sometimes we opt to use our internal TeamCity CI server and other times we use Travis CI for more transparency. This post will help you get your .NET Core application building in Travis CI by showing you the files you need in your publicly accessible Git repository.

Build.sh

You need a build script to the root of our repository for Travis CI to execute. It is quite simple.

#!/usr/bin/env bash
dotnet restore && dotnet build

You can add additional steps to the build.sh to run tests, but this is the simplest command you need.

.travis.yml

The .travis.yml is used by the service to construct your build environment. Add this to the root of your repository.

language: csharp
dist: trusty
sudo: required
mono: none
dotnet: 1.0.1
script:
  - ./build.sh --quiet verify

We do a few things in the configuration file:

  • set the language to csharp
  • set the linux distribution to trusty
  • allow for sudo access
  • turn off mono; we are running .NET Core now
  • select the dotnet container
  • execute our build script

Note, we could forgo calling our build.sh file and put the calls to dotnet in the script section of our configuration. We chose not to in this case. The Trusty version of Ubuntu is 14.04. Ubuntu 16.04 was released back in April of 2016, but Travis CI does not support it yet. Travis CI default distribution is 12.04, which is not supported by the .NET Core installer.

Conclusion

After adding the files, you can follow this basic tutorial to setting up your project. If everything goes right, you should have a successful build on Travis CI. It really takes very little effort and will help your contributors know if they broke the application.

Published October 26, 2016 by

undefined avatar
Khalid Abuhakmeh Director of Software Development (Former)

Suggested Reading