Sunday, January 31, 2016

Continuous Integration for .net Core projects ( for beginners )

Hello developers,

This article is about how you can easily setup continuous integration for your dot net core (dnx) projects with appveyor.com

Let's begin,

Step 1: Create an account and connect to repository

Create an appveyor account. It's free for open source projects.

Enable CI for for your desired repository as specified below :

Click on new Project


Select your source control
Add the repository

Step 2: Setup build Environment

Go to Settings of this project

Click on Environment



Select the Operating System as Visual Studio 2015 RC
Specifying Clone directory is optional.
In "Cached directories and files", we can put the location where packages and runtimes are stored so that it doesn't have to download them every time build runs. This reduces the build time.
Note that it is : C:\Users\appveyor\.dnx

Now click on Build tab

You now have 3 options,

  1. MSBuild
    • Build using msbuild. Easiest of all. You don't have to write any script. Appveyor will automatically detect the solution file and launch MSBuild to build your entire solution. That's it. That did work for me for conventional project but for coreclr project, I faced some issues.
  2. Script
    • I prefer using scripts because it gives me more flexibility of how I want to build my projects. Also, if I have the script, I can take these scripts and run them on a linux machine too because linux won't have MSbuild.
  3. Off
    • Well, we are using CI to build your application. No reason to to turn this Off!


Ok, Let's go through the build script now
Note that I have selected CMD from the type of scripts and not PS.

The first line of my build script adds a nuget package source. This is the nuget package source where all latest (or beta) packages are found for asp.net 5. This step was required for me because I needed one of those packages but you can safely omit this line if you don't need those packages.

Next I am upgrading the coreclr runtime and this command also tells the OS to use this as default runtime to run application. But we don't run the application on CI server, we just build it so, we don't need that line, right ? NO. Because we will be RUNNING some tests on CI server.

Next - I am now in the directory where appveyor has cloned my repository (c:\projects\<projectName>), so I know that there is an src folder and it contains some projects. I am going to build all projects one by one. dnu restore restores the nuget packages into C:\Users\appveyor\.dnx\packages. If you remember, we have cached this directory in Environments tab to avoid downloading packages every time it builds. Then dnu build compiles the project.

Click on Save.

Step 3: Setup Tests

Click on Tests tab.



Here too you have the option of "Auto" or "Script". I will again go with scripts. ( If you go with Auto, let me know your experience in comments).
I have a project called Tests. The first line changes the directory to go into that project folder.
Next, I restore the nuget packages required for this project.
Next command is "dnx test"

Wait, what ? how does dnx know how to run my tests ?!
Here's how:


I have a command specified in my project.json that simply calls xunit runner. dnx is able to run the commands specified in project.json. You can have multiple commands if you like, .. may be UnitTest, IntegrationTest, etc.

Step 4: Setup Build Notifications

Alright, now lets setup some email notifications to know if the build fails. Click on Notifications tab.



This diagram is actually pretty self explanatory. Just select "Email" as notification type, provide your email address(s), select the checkboxes as shown in diagram and save the settings.

Now whenever a check in is made in your repo, appveyor will automatically trigger a build and run all your unit tests. If it fails, you will get an email alert.

There you go. You have successfully set up continuous integration for your .net core project.

Feel free to explore all the options given to you in settings console. And please provide feedback in comments.

My next article will be about automated deployments. - aka Continuous Delivery.

Thank you.

Continuous Integration for .net Core projects ( for beginners )

Hello developers, This article is about how you can easily setup continuous integration for your dot net core (dnx) projects with appveyo...