Running dotCover Console Runner with MsTest - mstest

I partially found a solution to mstest with arguments:
https://devnet.jetbrains.com/thread/471980
Command Prompt (Works ok):
dotcover analyse /TargetExecutable="c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MsTest.exe" /TargetArguments="/testcontainer:c:\MyApps\Modules\UnitTests\bin\Debug\UnitTests.dll" /Output="C:\temp\AppCoverageReport.html" /ReportType="HTML"
However when using XML I get parse error:
<?xml version="1.0" encoding="utf-8"?>
<AnalyseParams>
<TargetExecutable>c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MsTest.exe</TargetExecutable>
<TargetArguments>/testcontainer:c:\MyApp\Modules\UnitTests\bin\Debug\UnitTests.dll</TargetArguments>
<Output>C:\Temp\AppCoverageReport.html</Output>
<ReportType>html</ReportType>
</AnalyseParams>
What am i doing wrong?

Turns out I was mistyping the name of the xml file (type)
dotcover analyse c:\Temp\coverangeconfig.xml => extra 'n'
instead of:
dotcover analyse c:\Temp\coverageconfig.xml
So, to use dotCover with MsText.exe the following work:
From command prompt
From XML file (coverageconfig.xml)
for both: see code above.
Make sure MsTest attribute "/testcontainer" is under /TargetArguments tag

Related

How do I force msbuild to create SARIF Files on CodeAnalysis

If I run the code analysis in Visual Studio 2022 (on a c++ project) I get a XML and a SARIF file for every code file.
No I try to run the code analysis with MSBuild 2022:
MSBuild.exe solution.sln -p:Configuration=Release /p:RunCodeAnalysis=true
But with this call I only get the code analysis XML files and no SARIF files.
Any idea how to force MSBuild to create the SARIF files?
Try to use following command line:
cl.exe <file/project path> /analyze:autolog:ext .nativecodeanalysis.sarif
Or
cl.exe <file/project path> /analyze:autolog:ext .sarif
Though MSBuild.exe invokes cl.exe to compile, it seems creating a .sarif file is only available for directly using cl.exe and its command.
Here’s the related document: Analysis log options
/analyze:autolog:ext extension
Overrides the default extension of the analysis log files, and uses extension instead. If you use the .sarif extension, the log file uses the SARIF format instead of the default XML format.
https://docs.microsoft.com/en-us/answers/questions/512275/what-to-do-with-static-code-analysis-result-xml-fi.html describes a solution:
Add a Directory.build.props file to your Visual Studio solution:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>$(ClOptions) %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
</ItemDefinitionGroup>
</Project>
Now I can extend my MSBuild Command line on my CI-Server (TeamCity):
/p:RunCodeAnalysis=true /p:ClOptions="/analyze:log%20MyApp.nativecodeanalysis.combined.sarif" (I had to replace the whitespace with %20).
And one SARIF file is generated, or if you want one SARIF file for every code file:
/p:RunCodeAnalysis=true /p:CaOptions="/analyze:log:format:sarif"
If you want to add additional command line switches you have to separate it with %20:
/p:CaOptions=/analyze:log:format:sarif%20/analyze:log:compilerwarnings
BUT: If I activate Clang-Tidy in my Visual Studio project I get the error CLANGTIDY : error : no such file or directory: '/analyze:log' [clang-diagnostic-error] and CLANGTIDY : error : unable to handle compilation, expected exactly one compiler job in ... - Does someone has an idea about that (except disabling Clang-Tidy)?

SonarQube Code Coverage from VSTS

I'm using VSTS hosted agent VS2017 to run the build, tests, and SonarQube analysis. I'm using the SonarQube extension from the marketplace (https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube). Task version in use is 4 which uses SonarQube Scanner for MSBuild 4.0.2.
The analysis works well, but it doesn't translate the code coverage results to the SonarQube. I can see the Code Coverage analysis in VSTS (build details), but not in SonarQube.
In my understanding, the problem is that VSTS generates a binary file with an extension .codecoverage. SonarQube doesn't know how to handle this file. I'm having trouble converting this to XML format as it seems I have no means to do it.
Has someone used VSTS successfully with SonarQube and got the Code Coverage results to SonarQube as well? How have you set it up?
EDIT 1
SonarQube version that I'm using is: Version 6.7 (build 33306), Community Edition
EDIT 2
The end of analysis actually generates the xml-file, like was stated in the comments below. This is from the logs:
2018-03-06T11:14:56.4189055Z 11:14:56.417 Attempting to locate the
CodeCoverage.exe tool...
2018-03-06T11:14:56.4210147Z 11:14:56.42 Attempting to locate the
CodeCoverage.exe tool using setup configuration...
2018-03-06T11:14:56.4345085Z 11:14:56.433 Code coverage command line tool:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Team
Tools\Dynamic Code Coverage Tools\CodeCoverage.exe
2018-03-06T11:14:56.4349101Z 11:14:56.434 Fetching code coverage report
information from TFS...
2018-03-06T11:14:56.4363869Z 11:14:56.435 Attempting to locate a test
results (.trx) file...
2018-03-06T11:14:57.0458245Z 11:14:57.044 Looking for TRX files in:
D:\a\1\TestResults, D:\a\1\s\TestResults
2018-03-06T11:14:57.0462747Z 11:14:57.045 Located a test results file:
D:\a\1\s\TestResults\VssAdministrator_factoryvm-az436_2018-03-
06_11_13_09.trx
2018-03-06T11:14:57.0600587Z 11:14:57.059 One code coverage attachment was
found in the trx file: factoryvm-az436\VssAdministrator_factoryvm-az436
2018-03-06 11_11_34.coverage
2018-03-06T11:14:57.0602504Z 11:14:57.059 Absolute path to coverage file:
D:\a\1\s\TestResults\VssAdministrator_factoryvm-az436_2018-03-
06_11_13_09\In\factoryvm-az436\VssAdministrator_factoryvm-az436 2018-03-06
11_11_34.coverage
2018-03-06T11:14:57.0691948Z 11:14:57.068 Executing file C:\Program Files
(x86)\Microsoft Visual Studio\2017\Enterprise\Team Tools\Dynamic Code
Coverage Tools\CodeCoverage.exe
2018-03-06T11:14:57.0692731Z Args: analyze
/output:D:\a\1\s\TestResults\VssAdministrator_factoryvm-az436_2018-03-
06_11_13_09\In\factoryvm-az436\VssAdministrator_factoryvm-az436 2018-03-06
11_11_34.coveragexml D:\a\1\s\TestResults\VssAdministrator_factoryvm-
az436_2018-03-06_11_13_09\In\factoryvm-az436\VssAdministrator_factoryvm-
az436 2018-03-06 11_11_34.coverage
2018-03-06T11:14:57.0694963Z Working directory:
D:\a\1\s\TestResults\VssAdministrator_factoryvm-az436_2018-03-
06_11_13_09\In\factoryvm-az436
2018-03-06T11:14:57.0695792Z Timeout (ms):60000
2018-03-06T11:14:57.0699007Z Process id: 3540
2018-03-06T11:14:58.7847582Z 11:14:58.783 Process returned exit code 0
2018-03-06T11:14:58.7858908Z 11:14:58.784 Updating project info files with
code coverage information...
The VSTS extension should automatically import the coverage results, but there is currently a regression that will be fixed (hopefully) soon: SONARMSBRU-339
Meanwhile, there is a workaround explained in the VSTS extension documentation in "Analysing a .NET solution": in the Additional Properties text area, add the following property:
sonar.cs.vscoveragexml.reportsPaths=**/*.coveragexml
I was unable to see the 'coveragexml' file even though I set 'sonar.verbose=true', 'system.debug=true'. Although, I found another way that works just fine, i.e. converting '.coverage' files into '.coveragexml' with PowerShell script:
Get-ChildItem -Path $(Agent.TempDirectory) -Include "*.coverage" -File -Recurse | % {
$outfile = "$([System.IO.Path]::GetFileNameWithoutExtension($_.FullName)).coveragexml"
$output = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName($_.FullName), $outfile)
"Analyse '$($_.Name)' with output '$outfile'..."
.$env:USERPROFILE\.nuget\packages\microsoft.codecoverage\15.8.0\build\netstandard1.0\CodeCoverage\CodeCoverage.exe analyze /output:$output $_.FullName
}
To make it work, make sure you have 'Inline PowerShell' task installed for the Marketplace and place it before 'Run Code Analysis' step in your build pipeline.
For those who use a self-hosted agent, you can also install Visual Studio Test Agent 2019.
It contains a CodeCoverage.exe file that the SonarQubeAnalyze#4 Azure DevOps task will find. SonarQube will be able to convert .coverage file into .coveragexml, according to this SonarQube documentation webpage.
Visual Studio Test Agent seems to be free. No need to pay for Visual Studio Enterprise.

Import C#.NET Code Coverage to SonarQube 5.1.2 using Visual Studio Code Coverage

I'm having a issue import .NET Coverage to SonarQube 5.1.2 using Visual Studio Code Coverage when following instructions on http://docs.sonarqube.org/pages/viewpage.action?pageId=6389770. I use sample Sonar project from Git. Here's my .bat file:
MSBuild.SonarQube.Runner.exe begin /k:"UTTestCSharp" /n:"UTTestCSharp" /v:"1.0" /d:sonar.cs.vscoveragexml.reportsPaths="MyDir/VisualStudio.coveragexml"
msbuild /t:rebuild
"C:/Program Files (x86)/Microsoft Visual Studio 12.0/Team Tools/Dynamic Code Coverage Tools/CodeCoverage.exe" collect /output:"MyDir/VisualStudio.coverage"
"C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/CommonExtensions/Microsoft/TestWindow/vstest.console.exe" "UnitTestProject1/bin/Debug/UnitTestProject1.dll"
"C:/Program Files (x86)/Microsoft Visual Studio 12.0/Team Tools/Dynamic Code Coverage Tools/CodeCoverage.exe" analyze /output:"MyDir/VisualStudio.coveragexml" "MyDir/VisualStudio.coverage"
MSBuild.SonarQube.Runner.exe end
The process just stop at the part generating VisualStudio.coverage, like this picture.
If I re-run the bat file then the process just skips the generating part and finishes success, but there's no Coverage report on Sonar Server. I need to see Code Coverage report on the Sonar Dashboard. Please help.
Try this command line. I found typos in SonarQube doc page. (For VS2015)
"C:\SonarQube\sonar-scanner-msbuild-2.3.1.554\MSBuild.SonarQube.Runner.exe" begin /v:1.0 /k:UTTestCSharp /n:UTTestCSharp
"C:\SonarQube\sonar-scanner-msbuild-2.3.1.554\MSBuild.SonarQube.Runner.exe" begin /v:1.0 /k:UTTestCSharp /n:UTTestCSharp /d:sonar.cs.vscoveragexml.reportsPaths=".\VisualStudio.coveragexml"
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" -p:Configuration=Release
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" collect /output:".\VisualStudio.coverage" "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" /EnableCodeCoverage ".\bin\Release\UTTestCSharp.dll"
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" analyze /output:".\VisualStudio.coveragexml" ".\VisualStudio.coverage"
Also add the "Generic Coverage" plugin. It has something to do with coverage report.

Configuring TFS 2013 has build issues with SonarQube

I have configured SonarQube to work with my TFS 2013. I followed the steps as mentioned in the setup doc. When i try to give a build from TFS online or Visual Studio, I am able to successfully complete the steps before Finish the analysis and upload the results to SonarQube.
I get the error No ProjectInfo.xml files were found. Check that the analysis targets are referenced by the MSBuild projects being built.
I am unable to figure out what might me causing the issue. I checked one of the links : No ProjectInfo.xml files were found error from command prompt using MSBuild SonarQube Runner v1.0 which speaks about the command prompt. Can someone point out where the issue is?
Below is the error log:
2015-09-12T11:44:10.9194896Z Output directory: C:\a\6fb08ad4\.sonarqube\out
2015-09-12T11:44:10.9194896Z Config file: C:\a\6fb08ad4\.sonarqube\out
2015-09-12T11:44:10.9204886Z 11:44:10 AM Loading the SonarQube analysis config from C:\a\6fb08ad4\.sonarqube\conf\SonarQubeAnalysisConfig.xml
2015-09-12T11:44:10.9204886Z 11:44:10 AM Attempting to locate the CodeCoverage.exe tool...
2015-09-12T11:44:11.3231261Z 11:44:11 AM Multiple versions of VS are installed: 11, 12, 14
2015-09-12T11:44:11.3240831Z 11:44:11 AM Code coverage command line tool: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe
2015-09-12T11:44:11.3240831Z 11:44:11 AM Fetching code coverage report information from TFS...
2015-09-12T11:44:11.3250829Z 11:44:11 AM Attempting to locate a test results (.trx) file...
2015-09-12T11:44:11.3250829Z 11:44:11 AM No test results files found
2015-09-12T11:44:11.3260828Z 11:44:11 AM Generating SonarQube project properties file to C:\a\6fb08ad4\.sonarqube\out\sonar-project.properties
2015-09-12T11:44:11.3270789Z ##[error]11:44:11 AM No ProjectInfo.xml files were found. Check that the analysis targets are referenced by the MSBuild projects being built.
2015-09-12T11:44:11.3270789Z 11:44:11 AM Writing processing summary to C:\a\6fb08ad4\.sonarqube\out\ProjectInfo.log
2015-09-12T11:44:11.3270789Z 11:44:11 AM Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.
2015-09-12T11:44:11.3280797Z 11:44:11 AM Creating a summary markdown file...
2015-09-12T11:44:11.3280797Z Process returned exit code 1
2015-09-12T11:44:11.3290776Z ##[error]Post-processing failed. Exit code: 1
2015-09-12T11:44:11.5740896Z ##[error]Unexpected exit code received from batch file: 1
2015-09-12T11:44:11.5790878Z ##[debug]summaryMdPath = C:\a\6fb08ad4\.sonarqube\out\summary.md
2015-09-12T11:44:11.5820880Z ##[debug]Uploading the summary.md file
Thanks!

Building InstallShield LE project with MSBuild - Error MSB4062

I work with Visual Studio 2012, and I just switched my deployment tools from NSIS to InstallShield. I've added new projects to my solution for InstallShield installers. When I build in Visual Studio (the IDE) I've no errors, no warnings and I'm happy.
Now, I want to have a script that build the full solution without launching the IDE. But when I run MSBuild in the command line, like that
MSBuild MySolution.sln /t:Build /p:Configuration=Release
I get following error MSB4062
C:\Program Files (x86)\MSBuild\InstallShield\2012SpringLimited\InstallShield.targets(21,3): error MSB4062: The "Microsoft.Build.Tasks.AssignProjectConfiguration" task could not be loaded from the assembly Microsoft.Build.Tasks.v3.5. Could not load file or assembly 'Microsoft.Build.Tasks.v3.5' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
My searches lead me to the conclusion that I must buy the Premier Edition of InstallShield to take profit of ISCmdBuild. But I can't afford it, and I think there might be another solution.
Any idea?
Using Fusion logging the MSBuild checks for the DLL here: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Microsoft.Build.Tasks.v3.5.DLL.
I copied
c:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Build.Tasks.v3.5.dll
to
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Build.Tasks.v3.5.dll
And the error is gone.
Alternatively open your *.isproj file and change from "3.5" to "4.0" on top on the tag:
<Project ToolsVersion="3.5"...> --> <Project ToolsVersion="4.0" ...>
Another solution is to force MSBuild to use the x86 platform. See https://stackoverflow.com/a/1074699/870604
If you're building from a TFS build, this can be configured from the build options:
I found the solution. Use the command devenv.exe instead of MSBuild.exe. It will be similar to launching Visual Studio and clicking the Build button. That's all!
devenv.exe MySolution.sln /build Release

Resources