I'm using the following code to generate a coverage report from a powershell script task in TFS 2015's Build Preview. I can run it on the build server and it generates the report correctly, but when it runs as part of the build it complains that there are no pdb files.
No results, this could be for a number of reasons. The most common reasons are:
1) missing PDBs for the assemblies that match the filter please review the output file and refer to the Usage guide (Usage.rtf) about filters.
2) the profiler may not be registered correctly, please refer to the Usage guide and the -register switch.
After doing a bit of Googling I discovered that /noshadow should have been enough, but it seems that the parameters for nunit are getting ignored. I'm assuming they're being ignored because the /nologo command should be stripping out the copyright info from being printed, but in the console output I can still see the information being displayed.
Also using the build output directory as the working directory should have fixed this as well, but using Set-Location didn't resolve the problem during the build.
This is the script that I'm currently running:
Param
(
[string] $SourceDir = $env:BUILD_SOURCESDIRECTORY,
[string] $UnitTestDir = "",
[string] $UnitTestDll ="",
[string] $Filter = "",
[string] $ExcludeByAttribute = "System.CodeDom.Compiler.GeneratedCodeAttribute",
[string] $nUnitOutputPath = "Output.txt",
[string] $nUnitErrorOutputPath = "Error.text",
[string] $XmlOutputPath = "_CodeCoverageResult.xml",
[string] $ReportOutputPath = "_CodeCoverageReport"
)
$openCoverPath = "E:\BuildTools\OpenCover.4.5.3723\OpenCover.Console.exe"
$nUnitPath = "E:\BuildTools\NUnit.Runners.2.6.4\tools\nunit-console.exe"
$reportGeneratorPath = "E:\BuildTools\ReportGenerator.2.1.1.0\ReportGenerator.exe"
$nUnitArgs = "$SourceDir\$UnitTestDir\$UnitTestDll /noshadow /nologo"
Write-Host "[Debug] Setting location to $SourceDir\$UnitTestDir"
Set-Location $SourceDir\$UnitTestDir
if (!(Test-Path $SourceDir\CodeCoverage)) {
New-Item $SourceDir\CodeCoverage -type directory
}
Write-Host "[Debug] Running unit tests from $SourceDir\$UnitTestDir\$UnitTestDll"
Write-Host "[Debug] Command: $openCoverPath -target:$nUnitPath -targetargs:""$nUnitArgs"" -filter:$Filter -excludebyattribute:$ExcludeByAttribute -register:user -output:""$SourceDir\CodeCoverage\$XmlOutputPath"""
& $openCoverPath -target:$nUnitPath -targetargs:"$nUnitArgs" -filter:$Filter -excludebyattribute:$ExcludeByAttribute -register:user -output:"$SourceDir\CodeCoverage\$XmlOutputPath"
Write-Host "[Debug] Generating report"
Write-Host "[Debug] Command: $reportGeneratorPath ""-reports:$SourceDir\CodeCoverage\$XmlOutputPath"" ""-targetdir:$SourceDir\CodeCoverage\$ReportOutputPath"""
& $reportGeneratorPath -reports:$SourceDir\CodeCoverage\$XmlOutputPath -targetdir:$SourceDir\CodeCoverage\$ReportOutputPath
Write-Host "[Debug] Finished running tests and generating report"