How Can We Help?
< All Topics

Integrate RKTracer with msbuild build C# Projects and generate code coverage

You should be able to build and test the application using the msbuild command in command line mode. To generate code coverage for the msbuild based application, you need to prefix rktracer to the msbuild command line to rebuild the application to instrument with the RKTracer tool.

msbuild prime.sln /t:rebuild


rktracer -v msbuild prime.sln /t:rebuild

RKTracer tool makes internal adjustments to msbuild build to instrument all the source files compiled. By default, rktracer instruments for multiple-condition code coverage, and you see the following code coverage information in the HTML report.

  • Function Coverage
  • Line Coverage 
  • Statement Coverage
  • Multi-Condition Code Coverage

Example msbuild:

Step 1: Enable RKTracer Tool

Before you enable the RKTracer tool for instrumentation, you need to clean the project, as the RKTracer tool will instrument the project at the source code level.

msbuild prime.sln /t:rebuild


rktracer -v msbuild prime.sln /t:rebuild

  • RKTracer instruments C# source file with “c:\rktracer/lib/librkliz-x86_64-w64-mingw32.exe ” and writes out the instrumented file “prime.cs” file in a preprocessed directory. Also, it stores the metadata, structure of instrumentation, and copy of source file content in JSON file. The tool will refer to rktracer.config for internal configuration at the time of instrumentation.
  • RKTracer automatically adds runtime library to msbuild build.

Step 2: Test instrumented application. 

You can perform unit testing/functional testing. In this case, it’s functional testing.

Post-testing, the RKTracer tool will save coverage data to the rk-coverage.txt file. If you test the instrumented application on the server machine, you need to copy an rk-coverage.txt file from the server machine to the application working directory to build the machine. 

Step 3: Generate Code Coverage HTML reports.

Once you have the rk-coverage.txt file, you can run the command “rkresults” to generate HTML reports. Ensure that you run the “rkresults” command in the application working folder or where we have the “rktracer” folder in your application.


rkresults command will search coverage data file “rk-coverage.txt” and map with JSON files (generated during instrumentation) in the rktracer folder and generate html reports. You can manually open the HTML report using index.html.

Generate code coverage for selected functions/files/folder

Generate coverage reports  for the selected folders






Suppose you need code coverage for source files from three different folders, i.e., core, keys, power, and ignore coverage for folders firmware_loader and lockdown. Edit rktracer.config in the RKTracer installation folder and go to the end of the file add the following information. 

ignore *.cs

instrument */power/* */core/* */keys/*

never */firmware_loader/* */lockdown/*

ignore *.cs = Ignores all C# source files from instrumentation

Instrument = Instrument source files from given folders

never = ignore selected folder  

Generate coverage reports only for selected functions from three different files.

fun_X() in source-file-X 

fun_Y() in source-file-Y

fun_Z() in source-file-Z

Suppose you need code coverage for selected functions from three different files. Edit rktracer.config in the RKTracer installation folder and go to the end of the file and set the following variables as shown below.  

ignore *.cs

instrument *source-file-X.cs *source-file-Y.cs *source-file-Z.cs

function-ignore *

function-instrument fun_X() fun_Y() fun_Z()

ignore *.cs = Ignore all C# programming source files

instrument *file-X.cs *file-Y.cs *file-Z.cs   = Instrument only these three source files.

function-ignore * = Then ignore all functions in the above three files.

function-instrument fun_X() fun_Y() fun_Z() = But instrument or don’t ignore these three functions from these three files.

Previous Code Coverage for dotnet Csharp projects in command line mode
Table of Contents