MicroMan
MicroMan

Reputation: 2098

Convert the last generated .Coverage into coveragexml for SonarQubee in TFS 2017

I am using .Net Core Test --collect "Code coverage" to generate a coverage file, I need to convert this for sonarqube, the issue is I do not nave the name of the file thats generated as its placed in a folder with a guid name and the file name itself is a GUID all under the TestResults folder

The following script works to convert .coverage files into coveragexml, but its for the whole working directory

Get-ChildItem -Recurse -Filter "*.coverage" | % {
$outfile = "$([System.IO.Path]::GetFileNameWithoutExtension($_.FullName)).coveragexml"
$output = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName($_.FullName), $outfile)
"Analyse '$($_.Name)' with output '$outfile'..."
. "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Team Tools\Dynamic Code Coverage Tools\codecoverage.exe" analyze /output:$output $_.FullName
}

But this converts the whole directory and after several days there are many builds, all I want to do it convert the .coverage file generated by the current build, so I need to be able to isolate the .coverage files generated by the current build.

Upvotes: 1

Views: 1419

Answers (1)

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41605

So you want to take only the last created code coverage file, you can filter the Get-ChiledItem results to get the last one:

Get-ChildItem -Recurse -Filter "*.coverage" | sort LastWriteTime | select -last 1

Upvotes: 2

Related Questions