SonarCloud not analysing .Net and SQL files

Hi,

I am struggling to get SonarCloud to analyse my project folder for both .Net C# and TSQL files. I can either run the MSBUILD scanner, or the Sonar Scanner. MSBUILD correctly analyses the solution and project files; but does not analyse the TSQL files.

If I use the Sonar Scanner, it will find the TSQL files but does not analyse the solution anymore.

How do I combine these two analyses? I would prefer not to have to create two separate build pipelines in Azure for this.

Some further details;

  • Azure Devops (pipeline and git)

  • Scanner command (azure pipeline)

    • task: SonarCloudPrepare@1
      displayName: ‘Prepare .Net Solution analysis configuration’
      inputs:
      SonarCloud: ‘Sonar Cloud (tradared)’
      organization: ‘tradared’
      scannerMode: ‘MSBuild’
      projectKey: ‘tradared’
      projectName: ‘tradared’

OR

- task: SonarCloudPrepare@1
  displayName: 'Prepare TSQL analysis configuration'
  inputs:
    SonarCloud: 'Sonar Cloud (tradared)'
    organization: 'tradared'
    scannerMode: 'CLI'
    configMode: 'manual'
    cliProjectKey: 'tradared'
    cliProjectName: 'tradared'
    cliSources: '.'
  • Languages within the repository: C#, TSQL (although named .sql & .tsql)
  • the potential workaround I see would be to create a second project in SonarCloud and have it operating with a specific Sonar Scanner CLI task, as well as the MSBUILD scanner on a different project.

hi @xpcros and welcome to the community!

You need to reference the TSQL files explicitly in the CSPROJ as resources (like they would be JS files in a web project, for example):

  <ItemGroup>
    <Content Include="JavaScript.js" />

The scanner for msbuild asks msbuild for all the resource files and then marks them as sonar.sources, and then during the END step , the sensors for all the languages of the sonar.sources files are invoked. If a CSPROJ has TSQL and JS “content”, the sensors for these languages will be invoked and do the analysis.

If the files are not references in the CSPROJ / VBPROJ project, they won’t be analyzed by the scanner for msbuild.

Yes, this is the other solution.

Thanks for the reply Andrei.

Would it be possible for me to drop the msbuild scanner; and just use the CLI scanner to analyse C# & SQL at the same time? If so, what configuration would I use to do this; I noticed that my CLI run settings above did not scan the C# files that were in repository along with the SQL files.

Thanks.
Paul

No.

You can read here how the analysis works and why the scanner for msbuild is needed.