Must-share information (formatted with Markdown):
Version information:
Enterprise Edition Version 7.6 (build 21501)
SonarQube task 4.6.3
TFS 2017 U2
Hey folks!
I’m having an issue with implementing SonarQube build task in TFS build definition for a certain project. The main problem is that all sources files are considered to be test files after running msbuild UNLESS you run vstests task after it’s completion.
GUID.sonar.sources=
GUID.sonar.tests=\ #huge list of all the files in the project
In the Run Analysis task:
.cs' generated metadata as test with charset 'UTF-8'
.cs' indexed as test with language 'cs'
I’m quite unsure why is this the case. I’ve checked project definition for Test project type GUID - none is present.
I noticed this in MSBuild task:
2019-08-13T14:51:05.2856481Z Task "GetAnalyzerSettings" (TaskId:31)
2019-08-13T14:51:05.2856644Z Task Parameter:AnalysisConfigDir=d:\agents\agent02-DEV\_work\17\.sonarqube\conf (TaskId:31)
2019-08-13T14:51:05.2856782Z Task Parameter:Language=cs (TaskId:31)
2019-08-13T14:51:05.2856957Z Task Parameter:CurrentProjectDirectoryPath=d:\agents\agent02-DEV\_work\17\s\AgentPortalWeb (TaskId:31)
2019-08-13T14:51:05.2857083Z Task Parameter:
2019-08-13T14:51:05.2857198Z OriginalAnalyzers=
2019-08-13T14:51:05.2857348Z ..\packages\Roslynator.Analyzers.2.0.0\analyzers\dotnet\cs\Roslynator.Common.dll
2019-08-13T14:51:05.2857526Z ..\packages\Roslynator.Analyzers.2.0.0\analyzers\dotnet\cs\Roslynator.Common.Workspaces.dll
2019-08-13T14:51:05.2857698Z ..\packages\Roslynator.Analyzers.2.0.0\analyzers\dotnet\cs\Roslynator.CSharp.Analyzers.CodeFixes.dll
2019-08-13T14:51:05.2857873Z ..\packages\Roslynator.Analyzers.2.0.0\analyzers\dotnet\cs\Roslynator.CSharp.Analyzers.dll
2019-08-13T14:51:05.2858029Z ..\packages\Roslynator.Analyzers.2.0.0\analyzers\dotnet\cs\Roslynator.CSharp.dll
2019-08-13T14:51:05.2858216Z ..\packages\Roslynator.Analyzers.2.0.0\analyzers\dotnet\cs\Roslynator.CSharp.Workspaces.dll (TaskId:31)
2019-08-13T14:51:05.2858514Z Task Parameter:OriginalRulesetFilePath=C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Team Tools\Static Analysis Tools\\Rule Sets\MinimumRecommendedRules.ruleset (TaskId:31)
2019-08-13T14:51:05.2858719Z Task Parameter:ProjectSpecificConfigDirectory=d:\agents\agent02-DEV\_work\17\.sonarqube\conf\0 (TaskId:31)
2019-08-13T14:51:05.2858863Z Task Parameter:IsTestProject=True (TaskId:31)
2019-08-13T14:51:05.2859044Z Reading config file: d:\agents\agent02-DEV\_work\17\.sonarqube\conf\SonarQubeAnalysisConfig.xml ... (TaskId:31)
2019-08-13T14:51:05.2859228Z Commencing retry-able operation. Max wait (milliseconds): 2500, pause between tries (milliseconds): 499 (TaskId:31)
2019-08-13T14:51:05.2859833Z Operation succeeded. Elapsed time (ms): 30 (TaskId:31)
2019-08-13T14:51:05.2860086Z Read config file successfully (TaskId:31)
2019-08-13T14:51:05.2860237Z Overwriting analysis settings for a test project... (TaskId:31)
2019-08-13T14:51:05.2860426Z Output Property: SQRuleSetFilePath=d:\agents\agent02-DEV\_work\17\.sonarqube\conf\SonarQubeRoslyn-cs-test.ruleset (TaskId:31)
2019-08-13T14:51:05.2860544Z Output Item(s):
2019-08-13T14:51:05.2860661Z SQAnalyzerFilePaths=
2019-08-13T14:51:05.2860812Z C:\Users\tfstask\AppData\Local\Temp\.sonarqube\resources\0\Google.Protobuf.dll
2019-08-13T14:51:05.2860981Z C:\Users\tfstask\AppData\Local\Temp\.sonarqube\resources\0\SonarAnalyzer.CSharp.dll
2019-08-13T14:51:05.2861146Z C:\Users\tfstask\AppData\Local\Temp\.sonarqube\resources\0\SonarAnalyzer.dll (TaskId:31)
2019-08-13T14:51:05.2861336Z Output Item(s): SQAdditionalFiles=d:\agents\agent02-DEV\_work\17\.sonarqube\conf\cs\SonarLint.xml (TaskId:31)
2019-08-13T14:51:05.2861487Z Done executing task "GetAnalyzerSettings". (TaskId:31)
which may or may not be related.
While i was writing this post, i decided to run Test Assembly right after msbuild, and what do you know? Now all files are classified as source files.
I am mighty confused (probably because i’m illiterate ape), but if someone could provide me some insight in what’s going on - i would be grateful.
UPDATE:
After successful results on one branch, i decided to attempt to replicate my stunning success on another branch. And apparently, 1 of 3 commits i did to the 1st branch while fiddling with .csproj files was also a contributor:
<PropertyGroup>
<!-- Mark the project as being a test project -->
<SonarQubeTestProject>false</SonarQubeTestProject>
</PropertyGroup>
Now, official docs never mention that you can do this (only true case), but this seemed to work in conjunction with running tests.
Now, I’m even more confused than before!