I finally started using GitHub for some of my projects. And as usual, I try what is possible 😉
This time, I played around with Continuous Integration. The way to go seems to be with Travis CI. It has (beta) support for .Net with Mono. And it seems to work quite well as long as your projects are Mono compliant.

Basic Travis usage in github
To use Travis in github is pretty straight forward. Just register for Travis, link to your github and add a .travis.yml file to your github project.
The basic file can look like:

language: csharp
solution: src/<yoursolution>.sln

This just compiles all the projects which are in your solution.

Skip / fix unsupported code when compiling with Mono
If you’re project is almost Mono compliant, you can think of using the precompiler directive with the variable __MonoCS__ to get it to build on mono as well but use the “real” thing in your Visual Studio.
Here’s an example which uses the CommandManager of WPF which does not exist in Mono:

#if __MonoCS__
        public event EventHandler CanExecuteChanged;
#else
        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }
#endif

This makes at least sure, that it compiles on Mono.

Using nUnit tests with Travis
To run nUnit tests with travis is also fairly easy. Just add your unittest project and modify the Travis file like this:

language: csharp
solution: ./src/yoursolution.sln

install:
  - sudo apt-get install nunit-console
  - nuget restore ./src/yoursolution.sln

script:
  - xbuild ./src/yoursolution.sln
  - nunit-console ./src/SomeLibrary.Tests/bin/Debug/SomeLibrary.Tests.dll

This installs the nunit-console package, makes sure that the nuget libraries are fetched, compiles your solution with xbuild and runs the test library with nunit-console.

That’s it. Now Travis compiles and tests your github project and fails in case that it can’t compile or at least one unit test fails.

Leave a Reply

Your email address will not be published.

*