Building .Net Core On Travis CI

.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.

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.