Travis CI continuous integration service officially supports many languages, but not C# or F#.
Can I use it with my .net projects?
Travis CI continuous integration service officially supports many languages, but not C# or F#.
Can I use it with my .net projects?
Travis CI now supports C#. Quoting liberally from that page:
Overview
The setup for C#, F#, and Visual Basic projects looks like this:
language: csharp
solution: solution-name.sln
mono:
- latest
- 3.12.0
- 3.10.0
Script
By default Travis will run xbuild solution-name.sln. Xbuild is a build tool designed to be an implementation for Microsoft's MSBuild tool. To override this, you can set the script attribute like this:
language: csharp
solution: solution-name.sln
script: ./build.sh
NuGet
By default, Travis will run nuget restore solution-name.sln, which restores all NuGet packages from your solution file. To override this, you can set the install attribute like this:
language: csharp
solution: solution-name.sln
install:
- sudo dosomething
- nuget restore solution-name.sln
See danielnixon's answer for the official way to do this now.
It is possible.
On your own mono machine, using the terminal, cd
into your solution directory and running the command xbuild
. This may automatically work, or it may not, as there are features you used in visual studio that need some tweaking in mono.
Things to look out for:
.csproj
linux has case sensitive paths where windows doesn't.export EnableNuGetPackageRestore=true
before running xbuild
if your project auto restores. mozroots --import --sync
to install them.nuget.*
instead of NuGet.*
references in your .csproj have been know to exist in various versions of nuget. .fsproj
to trigger the VS2012 configuration on non windows machines by adding '$(VisualStudioVersion)' == '11.0' Or $(OS) != 'Windows_NT'
see example.Unable to find framework corresponding to the target framework moniker '.NETPortable,Version=v4.0,Profile=ProfileX'. Framework assembly references will be resolved from the GAC, which might not be the intended behavior.
Use Platform Conditions (mentioned under Mono 3.0.11 or earlier) or upgrade to 3.1.2.<PropertyGroup Condition="$(OS) == 'Windows_NT'"> <TargetFrameworkProfile>Profile46</TargetFrameworkProfile> </PropertyGroup>
or Condition="$(OS) != 'Windows_NT'
for mono. Your mileage may vary. See working example..ci/nunit.sh
is my own shell script for nunit testing, checked into the root of the repo. So I can install the nunit-console version I want with nuget, and configure various include/excludes of categories too. Your mileage may vary, but this technique should work for xunit etc. Or do your own thing with xbuild or fake.
#!/bin/sh -x
mono --runtime=v4.0 .nuget/NuGet.exe install NUnit.Runners -Version 2.6.1 -o packages
runTest(){
mono --runtime=v4.0 packages/NUnit.Runners.2.6.1/tools/nunit-console.exe -noxml -nodots -labels -stoponerror $@
if [ $? -ne 0 ]
then
exit 1
fi
}
#This is the call that runs the tests and adds tweakable arguments.
#In this case I'm excluding tests I categorized for performance.
runTest $1 -exclude=Performance
exit $?
For testing the latest mono it's easiest to use Mac hosts (target by using language:objective-c
Mono v3.1.2 and later changed distribution on a Mac from a DMG to just a PKG so the install is quite simple.
This template should support Portable Class Libraries, .NET 4.5.1, and FSharp 3.1.
language: objective-c
env:
global:
- EnableNuGetPackageRestore=true
matrix:
- MONO_VERSION="3.8.0"
before_install:
- wget "http://download.mono-project.com/archive/${MONO_VERSION}/macos-10-x86/MonoFramework-MDK-${MONO_VERSION}.macos10.xamarin.x86.pkg"
- sudo installer -pkg "MonoFramework-MDK-${MONO_VERSION}.macos10.xamarin.x86.pkg" -target /
script:
- xbuild
- .ci/nunit.sh Tests/bin/Debug/Tests.dll
I's easy to use Mac hosts to setup up for a build matrix for multiple versions of Mono. See script below
language: objective-c
env:
global:
- EnableNuGetPackageRestore=true
matrix:
- MONO_VER="2.10.11"
- MONO_VER="3.0.12"
before_install:
- wget "http://download.mono-project.com/archive/${MONO_VER}/macos-10-x86/MonoFramework-MDK-${MONO_VER}.macos10.xamarin.x86.dmg"
- hdid "MonoFramework-MDK-${MONO_VER}.macos10.xamarin.x86.dmg"
- sudo installer -pkg "/Volumes/Mono Framework MDK ${MONO_VER}/MonoFramework-MDK-${MONO_VER}.macos10.xamarin.x86.pkg" -target /
script:
- xbuild
- .ci/nunit.sh Tests/bin/Debug/Tests.dll
And now you should be good to go to use travis on your c# project.
That's the key point - the project must work on Mono. This mostly works for library-style projects (AWS SDK .NET is a good example) though requires more development efforts and discipline. Linux building environment won't work if you are developing a project for Windows platform such as WPF application, Azure cloud service, Windows Phone/Store app or even ASP.NET Web API.
AppVeyor CI is a hosted continuous integration service for Windows platform and it's free for open source projects. It's like Travis CI for Windows!
You can setup build process for VS.NET solution, custom MSBuild project, PSake or any PowerShell script of batch file. Besides, AppVeyor has built-in artifacts management and deployment framework.
As already mentioned, Travis CI has beta support for C#. I'ts straight forward to use. Also nunit can be integrated very easily. Here's a small example of a .travis.yml file which runs nunit tests and marks the build as failed if at least one unit test fails:
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
If you want to use Travis CI with F#, on GitHub, with FAKE and Packet, then the F# ProjectScaffold is recommended:
http://fsprojects.github.io/ProjectScaffold