Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
.NET Core Open Cover powershell script
Param (
[switch] $generateReport,
[switch] $uploadCodecov
$currentPath = Split-Path $MyInvocation.MyCommand.Path
$coverageOutputDirectory = Join-Path $currentPath "coverage"
$coverageFile = "coverage-results.xml"
Remove-Item $coverageOutputDirectory -Force -Recurse -ErrorAction SilentlyContinue
Remove-Item $coverageFile -ErrorAction SilentlyContinue
nuget install -Verbosity quiet -OutputDirectory packages -Version 4.6.519 OpenCover
$openCoverConsole = "packages\OpenCover.4.6.519\tools\OpenCover.Console.exe"
# OpenCover currently not supporting portable pdbs (
$configuration = "Coverage"
$csprojPath = "test\Bazinga.AspNetCore.Authentication.Basic.Tests"
cmd.exe /c $openCoverConsole `
-target:"c:\Program Files\dotnet\dotnet.exe" `
-targetargs:"test -c $configuration $csprojPath.csproj" `
-hideskipped:File `
-output:$coverageFile `
-oldStyle `
If ($generateReport) {
nuget install -Verbosity quiet -OutputDirectory packages -Version ReportGenerator
$reportGenerator = "packages\ReportGenerator.\tools\ReportGenerator.exe"
cmd.exe /c $reportGenerator `
-reports:$coverageFile `
-targetdir:$coverageOutputDirectory `
# requires variable set: CODECOV_TOKEN
If ($uploadCodeCov) {
nuget install -Verbosity quiet -OutputDirectory packages -Version 1.0.1 Codecov
$Codecov = "packages\Codecov.1.0.1\tools\Codecov.exe"
cmd.exe /c $Codecov -f $coverageFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment