/
Legacy .NET agent - Setting up IIS

Legacy .NET agent - Setting up IIS

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 settings 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"

Coverage Collector IIS Installation

As an Administrator, install and start the coverage collector service: 

SL.DotNet.CoverageCollectorService.exe install start

Register our agent as a profiler in the IIS services

SL.DotNet.exe registeriis {--token  <arg> | --tokenFile <arg>}

Perform IIS reset:

iisreset /restart

At the successful completion of this step, you will see a new entry appearing in the Cockpit > Agent Monitor for an entity called CollectorService for dotnet technology

This installation step is updating the following keys in the Windows Registry

  • System\CurrentControlSet\Services\W3SVC

  • System\CurrentControlSet\Services\WAS

Those keys are updated with a Multi-String value called 'Environment' containing the following

Cor_Enable_Profiling=1 Cor_Profiler={01CA2C22-DC03-4FF5-8350-59E32A3536BA} COR_PROFILER_PATH_32=<PATH TO SL.DotNet.ProfilerLib_x86.dll> COR_PROFILER_PATH_64=<PATH TO SL.DotNet.ProfilerLib_x64.dll> SL_CollectorId=GlobalCollector

In case of testing is executed from within a PowerShell script, the provided environment variables need to be defined using the Set-Item command to be accessible by the PowerShell-spawned processes.

Set-Item Env:Cor_Enable_Profiling 1 Set-Item Env:Cor_Profiler {01CA2C22-DC03-4FF5-8350-59E32A3536BA} Set-Item Env:COR_PROFILER_PATH_32 <PATH TO SL.DotNet.ProfilerLib_x86.dll> Set-Item Env:COR_PROFILER_PATH_64 <PATH TO SL.DotNet.ProfilerLib_x64.dll> Set-Item Env:SL_CollectorId GlobalCollector

Capturing coverage

During the time you want to run your tests and capture coverage, you can now start and stop the coverage collection of the SeaLights agent test listener

Starting coverage collection session

Before you start running your tests, you need to update the SeaLights Test Listener to start collecting coverage. You do so with the startCollectorServiceSession command.

Since there could be multiple applications running on a single IIS server, it is important to make note of the Application Pool name that corresponds to the hosted application from which coverage will be collected. If you are unsure what your application pool name is for the processTag parameter, refer to the expandable paragraph below (inside this article section) to identify it manually from your IIS Manager console.

SL.DotNet.exe startCollectorServiceSession --buildSessionIdFile buildSessionId.txt --labId my_labId --processName w3wp.exe --processTag DefaultAppPool --includeChildProcesses true

For .NET Core processes, set --processName dotnet, as this is the name of the process on which .NET Core applications run.

At the successful completion of this step, you will see additional new entries appearing in the Cockpit > Agent Monitor: the CollectorServiceSession and a entity Profiler.
The Profiler will be highlighting the Application Pool it is connected to as a Tag in the dedicated column.

  • You can provide a star ('*') to the processTag parameter in order to capture all the Application Pools at once.
    This option can be used for troubleshooting or if your IIS server is dedicated to your application but is not necessarily defined as a best practice.

  • This command can be run on a remote machine (like the CI running the tests) while providing the host to start the session on using the parameter: --machine <IIS host> 

To retrieve the Application Pool name:

  1. Open the IIS Manager:

    • Either browse to Control Panel → Administrative Tools → Internet Information Services (IIS) Manager

    • Open a new Run prompt (⊞ Win+R) and type inetmgr

  2. On the left side Pane, browse to your IIS instance.

  3. Select "Application Pools" to see a list of all currently configured application pools.

    • The name displayed here corresponds to the Application Pool name you will need to configure in later steps:

  4. Alternatively, on the same pane you can browse to the Site under which your application is hosted, Right click on the application, and select "Advanced Settings":

  5. In the popup window, the first line - Application Pool, corresponds to the name of the application pool to be used:

Running your tests

Now you can run any one of your tests that run against this IIS instance and capture coverage (Don’t forget to send a start and end command with the test stage name):

See 'SeaLights .NET agent - Running tests' for details of how to run tests

Stopping coverage collection session

SL.DotNet.exe stopCollectorServiceSession --stopAllSessions --processName w3wp.exe --processTag DefaultAppPool

Note: This command can be run on a remote machine (like the CI running the tests) while providing the host to start the session on it, using the parameter: --machine <IIS host> 

Un-installing the Coverage Collector Service

Sometimes when upgrading your agent version, you will need to uninstall the coverage collector service from your machine.

This can be done by running the following command:

SL.DotNet.CoverageCollectorService.exe uninstall

See 'SeaLights .NET - command reference' for full parameter details

Sample script

# ===== SECTION TO UPDATE ==== $SL_DOMAIN="mycompany.sealights.co" $SL_TOKEN="123456789" #Prefer an Env variable from your Credentials Manager # Env specific $SEALIGHTS_PATH="C:\Sealights\" $SL_AGENT_PATH="$SEALIGHTS_PATH\SL.DotNet\" $SL_BSID_FILE="$SEALIGHTS_PATH\buildSessionId.txt" #App specific $IIS_AppPool="DefaultAppPool" $SL_ENV_LABID="TestLabEnv@Automation" # ============================ [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $previousProgressPref=$global:ProgressPreference $global:ProgressPreference = "SilentlyContinue" #Disable Progress bar to speed up download and expand ### Install .Net Prerequisites here if required ### ### Install Agent and Token ### Write-Output "Retrieve version from Sealights settings..." $slHeader=@{'Accept'='application/json'; 'Authorization'="Bearer $SL_TOKEN"} $SLSettingsVersion = ((Invoke-WebRequest -Uri https://$SL_DOMAIN/api/v2/agents/dotnet/recommended -UseBasicParsing -Headers $slHeader).Content | ConvertFrom-Json | Select-Object agent).agent.version Write-Output "Download Sealights DotNet agent set in settings..." Invoke-WebRequest -OutFile $SEALIGHTS_PATH\sealights-dotnet-agent.zip -UseBasicParsing -DisableKeepAlive -Uri http://agents.sealights.co/SL.DotNet/SL.DotNet-$SLSettingsVersion.zip Write-Output "Expanding downloaded archive and placing token..." Expand-Archive $SEALIGHTS_PATH\sealights-dotnet-agent.zip -DestinationPath $SL_AGENT_PATH -Force Remove-Item -Force .\sealights-dotnet-agent.zip Get-ChildItem -Directory -Path .\SL.DotNet\ | Foreach-Object { $SL_TOKEN | Out-File -NoNewline -Force (Join-Path $_.FullName "sltoken.txt") } Write-Output "Sealights agent version used is: $(Join-Path -Path $SL_AGENT_PATH -ChildPath 'version.txt')" ### Install SL Collector Service ### Invoke-Expressin $SL_AGENT_PATH\x64\SL.DotNet.CoverageCollectorService.exe install start #Register SL service into IIS Invoke-Expression $SL_AGENT_PATH\x64\SL.DotNet.exe registeriis Invoke-Expression iisreset /restart # Starting session for specific app version Invoke-Expression $SL_AGENT_PATH\x64\SL.DotNet.exe startCollectorServiceSession --buildSessionIdFile $SL_BSID_FILE --processName w3wp.exe --processTag $IIS_AppPool --includeChildProcesses true --logEnabled true --logAppendConsole true --labId $SL_ENV_LABID $global:ProgressPreference = $previousProgressPref #Restore progress bar #### You can start your tests ####

Related content