Edited on 2018-01-15:

I have added a new article describing the same process but using .NET Core (using a library targeting .NET Standard).



I recently built a C# library to access the New York City MTA service status feed.
This project includes unit tests built with the NUnit framework and it was my first shot at using Tavis CI.

It is fairly easy to find examples of the .travis.yml file including the apt-get commands installing mono but it isn’t required anymore.
Travis CI has now an easier way of doing things when it comes to building C# (even if it is stated that this is beta and that it could be removed at anytime…)

Here is what the .travis.yml file I used ended up looking:

1
2
3
4
5
6
7
8
language: csharp
solution: solution-name.sln
before_install:
  - sudo apt-get install nunit-console
before_script:
  - nuget restore solution-name.sln
after_script:
  - nunit-console Tests/bin/Release/Tests.dll

The first and second lines are obvious and documented.
But using NUnit is not and requires the console to be installed (line 4) and run using the test project output (the .dll file, line 8).
Release (which is the default) can be replaced by the build configuration you are using using the following .travis.ymlfile sample:

1
2
3
4
5
6
7
8
9
language: csharp
script:
  - xbuild /p:Configuration=Debug solution-name.sln
before_install:
  - sudo apt-get install nunit-console
before_script:
  - nuget restore solution-name.sln
after_script:
  - nunit-console Tests/bin/Debug/Tests.dll

Line 3 and 9 need to be adapted to your build configuration (Debug might need to be changed to match your configuration name).

You can see a “real life” example here: MTAServiceStatus on Github
Associated Travis CI badge: Build Status
Travis CI configuration used for this project: .travis.yml file on master