Building Your ASP.NET Core Project on AppVeyor

AppVeyor is a great continuous build/delivery service which is hosted in the cloud. You can think of it as a hosted alternative to TeamCity or Visual Studio Online. One of the best things is that it is free for open source projects. This makes it a popular choice for something like GenFu, our test data generation tool.

There are a couple of ways to set up AppVeyor for building a project like GenFu. You can put in place an AppVeyor.yml file which gives instructions about which steps to run to generate a build. Alternately you can put in place a powershell script to do the building. I opted for the latter because it is more portable to other build tools should it be necessary.

The first thing to do is to set up an AppVeyor account and hook it up to your source control. I signed in with github credentials so it was easy to locate the GenFu project which is, of course, hosted on github.

In the build tab I put in just a call to a powershell script.

Imgur

I also disabled the test task. This is because AppVeyor, at the time of writing, doesn’t really understand how to call dnx based tests. No big deal we’ll do that in our build scripts. AppVeyor does have the dotnet version manager installed so we can skip the step of downloading that and just make use of it.

dnvm list
dnvm install 1.0.0-rc1-update1 -r coreclr -a x86
dnvm install 1.0.0-rc1-update1 -r clr -a x86
dnvm install 1.0.0-rc1-update1 -r coreclr -a x64
dnvm install 1.0.0-rc1-update1 -r clr -a x64
dnvm list
dnvm use 1.0.0-rc1-update1 -a x64 -r coreclr

Here I’ve listed out the current environments then installed the latest versions of the runtime. This could probably be done implicitly so our builds were always using the latest. I would actually discourage that because we don’t want our builds to start failing when we haven’t made changes fixing on a very specific version is desirable. Now we have everything installed we can call the build itself.

dnu restore
#run the build
& "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" src\GenFu.sln

First we restore all the packages. In theory the msbuild script should probably do that but I did run into some errors as a result of not calling dnu restore so I’d recommend it. Again we’re being very specific here using version 14 of MSBuild. No previous version understands how to do DotNet Core builds so we’ll focus on version 14.

Finally we need to run our tests. GenFu makes use of XUnit because

A) It is awesome
B) Brad Wilson who maintains it is awesome

#tests
dnvm use 1.0.0-rc1-update1 -a x64 -r coreclr
dnx -p tests\GenFu.Tests test -xml xunit-results.xml

I did find some documentation which suggested that you had to produce an XML file and upload it using

# upload results to AppVeyor
$wc = New-Object 'System.Net.WebClient'
$wc.UploadFile("https://ci.appveyor.com/api/testresults/xunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\xunit-results.xml))

However I think that AppVeyor was able to parse the test results without that doing that so YMMV.

Now GenFu has a handy build all set up and we can proudly display a badge in our Readme so people can see that we are building and testing continuously.

Build status