New to Coco v4.3.3 is the ability to instrument a .NET Core application on Linux, for use in obtaining code coverage metrics for such applications. This blog will walk you through how to instrument a simple .NET Core application written in C# and built on Linux. We will then demonstrate using Squish Coco to analyze the code coverage data for the application. 

A Simple .NET Program

We’ll use Microsoft’s “Hello World!” tutorial as our application. The program prints the statement “Hello World!” and the current time to the console. Prior installation of the .NET SDK is a requirement for this tutorial, as is a Squish Coco installation in the root directory.

The program file consists of the following code: 

using System;

namespace myApp
      class Program
           static void Main(string[] args)
                Console.WriteLine("Hello World!");
                Console.WriteLine("The current time is " + DateTime.Now);

To run the program, issue the following in a terminal:

$ dotnet run

If the program ran successfully, the console should return:

Hello World!
The current time is 12/3/2019 4:16:25 PM

Instrumenting the Application

There are two methods to instrumentation, one method most suitable to those engineers who typically do not have access to the project files and source (e.g., a test or QA engineer), and a second method most suitable to those who develop the code. We will explore both methods.

Method 1: No Access to Source Files

First, clean the project directory:

$ dotnet clean

Set an environment variable to activate the code coverage:


Then, rebuild the project:

$ dotnet build

Finally, run the project:

$ dotnet run

A *.csexe and *.csmes file will generate. Open these in the CoverageBrowser:

$ coveragebrowser -m ./obj/Debug/netcoreapp3.0/myApp.dll.csmes -e myApp.dll.csexe

The reported code coverage is 100%, as shown in the image above.

Method 2: Access to the Project Files

In this method, we will edit the *.csproj file delivered with the tutorial to include a statement to activate the code coverage.

Open myApp.csproj, and add the following line within the PropertyGroup bracket:


The complete myApp.csproj file should look like the following:

<Project Sdk="Microsoft.NET.Sdk">


Save the file. Next, as in Method 1, clean, build, and run the project:

$ dotnet clean
$ dotnet build
$ dotnet run

Similar to Method 1, we can open the coverage results in the CoverageBrowser:

$ coveragebrowser -m ./obj/Debug/netcoreapp3.0/myApp.dll.csmes -e myApp.dll.csexe

Again, we see 100% statement coverage.


The above methods demonstrate instrumenting a simple .NET Core project on Linux, for obtaining code coverage data for the program using Squish Coco. Note that no changes to the actual source code were required, only minor modifications to the .csproj file, and in the case of Method 1, no changes to the project were required at all.


Informative blog, Nicholas. Both the methods of accessing files are nicely explained. There is no need to make any changes to the project files. The blog will be helpful for those working on .Net Core applications on Linux. The examples in the blog make it easy to follow and understand.

    Dear Samaira,

    Thank you for the very positive feedback! I’m glad you found the examples in the blog easy to follow.

    Kind regards,


Leave a Reply

Your email address will not be published. Required fields are marked *

Copy link
Powered by Social Snap