Skip to content

.NET

When the built-in .NET runner ships, it will:

  • Accept lang: dotnet in nolapse.yaml.
  • Invoke dotnet test --collect:"XPlat Code Coverage" automatically.
  • Parse the Cobertura XML report produced by Coverlet to extract line coverage.
  • Respect the same warn_threshold / fail_threshold / strict_mode settings as all other runners.

The expected nolapse.yaml when it is available:

lang: dotnet
warn_threshold: -1.0
fail_threshold: -5.0
strict_mode: false

Until the built-in runner ships you can invoke dotnet test with Coverlet and parse the resulting JSON summary.

Terminal window
dotnet add package coverlet.collector

Or for MSBuild integration:

Terminal window
dotnet add package coverlet.msbuild

Create nolapse-runner.sh at the repo root:

#!/usr/bin/env bash
set -euo pipefail
REPO_PATH="${1:-.}"
cd "$REPO_PATH"
# Run tests and produce a JSON summary via coverlet
dotnet test --collect:"XPlat Code Coverage" \
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=json \
DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.OutputFormat=json
# Find the most recently written coverage.json
COVERAGE_FILE=$(find . -name "coverage.json" -newer nolapse.yaml 2>/dev/null | head -1)
if [ -z "$COVERAGE_FILE" ]; then
echo "nolapse-runner: coverage.json not found" >&2
exit 1
fi
PCT=$(python3 -c "
import json, sys
data = json.load(open('$COVERAGE_FILE'))
lines_covered = sum(v.get('Summary', {}).get('LinesCovered', 0) for v in data.values())
lines_total = sum(v.get('Summary', {}).get('LinesTotal', 0) for v in data.values())
print(f'{(lines_covered / lines_total * 100):.1f}' if lines_total else '0.0')
")
echo "nolapse-coverage: ${PCT}"

Make it executable:

Terminal window
chmod +x nolapse-runner.sh
lang: custom
warn_threshold: -1.0
fail_threshold: -5.0

Run nolapse:

Terminal window
NOLAPSE_RUNNER_PATH=./nolapse-runner.sh nolapse run --repo .

See Custom Runner for the full runner contract.

Watch the nolapse changelog and the .NET runner issue for updates.