On several GitHub projects nowadays you find these nice badges in the readme.md that tell you whether the current build passed. Until a few days ago I didn’t know how these were implemented but since I have my own small open-source GitHub project now, I wanted a badge. Sounds a bit like gamification if I say it like this but that’s an entirely different topic :)

The badge I’m aiming for is this one: AppVeyor badge It’s from AppVeyor, a continuous delivery service for Windows. Out-of-the-box it supports msbuild. Since my project is ASP.NET Core (RC1) with an xUnit.net test suite, some configuration must be added to the project.

Add project to AppVeyor

Adding your GitHub project itself to AppVeyor is really easy: just login to https://ci.appveyor.com/login with your GitHub account credentials and the rest should point itself.

AppVeyor configuration

Next step is to add an appveyor.yml to the root folder of your project. You can check out my most recent version here. I’ll list it here to be able to explain the parts.

version: 1.0.{build}
# For now just the develop branch.

# Defines the machine that is used to run build/test/deploy/...
os: Visual Studio 2015

# Called after cloning the repository.
  # Add the v3 NuGet feed and myget.org (for moq.netcore package).
  - nuget sources add -Name api.nuget.org -Source https://api.nuget.org/v3/index.json
  - nuget sources add -Name myget.org -Source https://www.myget.org/F/aspnet-contrib/api/v3/index.json
  # Install dnvm.
  - ps: "&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}"
  # Install coreclr (no need for startup improvement here)
  - dnvm upgrade -r coreclr -NoNative

# Called before building.
  - dnu restore
  - cd %APPVEYOR_BUILD_FOLDER%\src\Localization.JsonLocalizer

# Replace default build.
build: off
  - dnu build

# Called before running tests.
  - cd %APPVEYOR_BUILD_FOLDER%\test\Localization.JsonLocalizer.Tests

# Replace default test.
test: off
  - dnx test

My configuration has three stages:

  • Install ASP.NET Core RC1.
  • Prepare and run dnu build.
  • Prepare and run dnx test

Some details worth noting:

  • By default the Visual Studio 2015 build machine is configured with the v2 NuGet feed. I add the v3 feed and the myget.org feed because that’s where the moq.netcore package lives that I use in my xUnit tests.
  • I use the -NoNative flag for dnvm upgrade. This skips native image generation to improve startup time. The only thing that needs starting up are unit tests and these run just once. Native image compilation costs way more time than I can win back in unit test startup time improvements.
  • AppVeyor defines a number of environment variables, one of which is APPVEYOR_BUILD_FOLDER that points to the folder that the project was cloned into.

##Results On the AppVeyor overview page, the result of a successful build is this: This result includes both the build and the tests. You already saw the badge that I included in my readme.md file. The badge itself is an SVG image that is generated to describe your latest build result.

So that’s it, pretty easy once you understand how it works. I didn’t invent all of this myself of course; there’s a nice post by Nimesh Manmohanlal that handles the installation steps. I added the necessary build and test steps.