Legacy .NET agent - Capturing coverage from a windows process

There are two ways to capture coverage from windows processes using the SeaLights .NET agent

  1. By running the process with our agent using the testListener option

  2. By running the SeaLights .NET agent as a background listener

The Background Listener option allows you to capture coverage from any application without changing the command you use to run it but requires more steps than testListener option.

Prerequisites

Microsoft run-time components

Install Microsoft Visual C++ Redistributable for Visual Studio 2017 from: https://www.visualstudio.com/downloads/

You can use the PowerShell commands below to install these prerequisites via a script

iwr -OutFile vc_redist.x86.exe -UseBasicParsing -Uri https://go.microsoft.com/fwlink/?LinkId=746571 Start-Process -FilePath vc_redist.x86.exe -ArgumentList "/Q" -Wait iwr -OutFile vc_redist.x64.exe -UseBasicParsing -Uri https://go.microsoft.com/fwlink/?LinkId=746572 Start-Process -FilePath vc_redist.x64.exe -ArgumentList "/Q" -Wait

Agent Token and Proxy settings

If needed, configure the coverage collector service by editing the SL.DotNet.CoverageCollectorService.exe.config file:

  • If you have not placed the sltoken.txt in the agents' folder, then in Sealights.Token put the token you've received from SeaLights

  • If a proxy is used, add a key named 'Sealights.Proxy' and set the value to a URL like "http://127.0.0.1:8888"

Running the process with the SeaLights .NET agent using the testListener option

To capture coverage from a single application, you can run it with the SeaLights .NET agent, which will capture coverage from it when it runs, and tests are run against it.

SL.DotNet.exe testListener --buildSessionIdFile buildSessionId.txt --labId my_labId --target c:\MyApplication\App.exe --workingDir c:\WorkingDir --targetArgs "-Flag1 true MyTest.dll"

The sample command above is replacing the regular command used to startup the application captured: c:\MyApplication\App.exe -Flag1 true MyTest.dll executed from the c:\WorkingDir directory

At the successful completion of this step, you will see new entries appearing in the Cockpit > Live Agents Monitor: the testListener and a entity called Profiler with the version details of your application.

Running the SeaLights .NET agent as a background listener

To capture coverage from any application without changing the command you run, you can execute the SeaLights .NET agent as a background process, which will capture coverage from any process with the SeaLights .NET agent attached as a profiler.

The expected steps are then:

  1. Start the Sealights .NET background listener

  2. Set up the environment variable to enable the Sealights .NET Profiler

  3. Start your application

Starting the SeaLights .NET agent background listener

To run the background process, you use the startBackgroundTestListener flag and provide a unique session key:

SL.DotNet.exe startBackgroundTestListener --buildSessionIdFile buildSessionId.txt --labId my_labId --testListenerSessionKey SL_CovCollectorAgent

Setting the SeaLights .NET agent as a profiler

Now, you need to run (all) your processes - i.e., including your application - with the SeaLights .NET agent defined as a profiler before starting your application.
This is done by setting the following environment variables in the shell used to run your process:

  • Cor_Profiler set to {01CA2C22-DC03-4FF5-8350-59E32A3536BA}

  • Cor_Enable_Profiling set to 1

  • Cor_Profiler_Path_32 set to the path of SL.DotNet.ProfilerLib_x86.dll

  • Cor_Profiler_Path_64 set to the path of SL.DotNet.ProfilerLib_x64.dll

  • SL_CollectorId set to the same session key provided to the startBackgroundTestListener command

Setting the environment variables for the Profiler agent

You can use the following PowerShell commands to declare the environment variables required by the agent to attach to your application as a Profiler

If you’re using CMD, you can use the following commands

In TeamCity, you can use the dedicated service message in your build script to dynamically update these build parameters right from a build step so that the following build steps will run with a modified set of build parameters.

Stopping the SeaLights .NET agent background listener

Once you have finished collecting coverage from the process, you need to stop the background listener. This is done by using the stopBackgroundTestListener flag with the session key previously used