- ALM used: Azure DevOps
- CI system used: Azure DevOps
- Languages of the repository: C#
My problem is that SonarCloud is only analyzing my test file, and not my actual project files. When I view the results from the UI it is as though it only detected test files.
In the below folder structure, functions.csproj gets ignored, but functions.tests.csproj gets analyzed correctly.
I have a c# solution with this structure:
- src/
-- some.code.functions/some.code.functions.csproj
- tests/
-- some.code.functions.tests/some.code.functions.tests.csproj
My build pipeline is configured like this:
steps:
- checkout: self
fetchDepth: 0
- task: SonarCloudPrepare@1
inputs:
SonarCloud: 'SonarCloud'
organization: 'xxx'
scannerMode: 'MSBuild'
projectKey: xxx
projectName: xxx
extraProperties: |
sonar.verbose=true
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '6.x'
includePreviewVersions: true
- task: DotNetCoreCLI@2
displayName: Build
inputs:
command: build
projects: |
$(System.DefaultWorkingDirectory)/$(FunctionDirectory)/*.csproj
arguments: --output $(System.DefaultWorkingDirectory) --configuration Release -verbosity:diag /p:RunAnalyzersDuringBuild=true
- task: DotNetCoreCLI@2
displayName: Test
inputs:
command: test
projects: ${{ parameters.FunctionTestPath }}/*.Tests/*.csproj
arguments: '--collect "Code coverage"'
- task: SonarCloudAnalyze@1
- task: SonarCloudPublish@1
inputs:
pollingTimeoutSec: '300'
I also get the warning on my analysis ‘Your project contains only TEST-code for language C# and no MAIN-code for any language, so only TEST-code related results are imported.’ But when I check the output of the Build task it reports that it was categorizes as Main code:
Task "Message" (TaskId:91)
Task Parameter:Text=Sonar: (some.code.functions.csproj) categorized as MAIN project (production code). (TaskId:91)
Task Parameter:Importance=normal (TaskId:91)
Sonar: (some.code.functions.csproj) categorized as MAIN project (production code). (TaskId:91)
Done executing task "Message". (TaskId:91)
Task "Message" skipped, due to false condition; ($(SonarQubeTestProject)=='true') was evaluated as (False=='true').
I have saved the output of the SonarCloudAnalyze step. If you require this file please DM me so I can send it to you.