Typescript files are not analyzed with Scanner for MSBuild

We have two ASP.NET core 2.2 project with a seperate folder for shared Typescript code. When we build the ASP.NET core project with MSBuild the Typescript folder which is used is not analyzed by SonarScanner. The Typescript code is build with Yarn tasks.

How do we make sure that the Typescript code is analysed within the Azure DevOps build pipeline?

SonarCloud private
SonarScanner for MSBuild 4.6.2

Hi,

2 questions :

  • Do you want your .ts files to be analysed, or only the resulted js after the compilation ?
  • Are you sure that the file you want to analyse are well checkout on the file system where your agent is located ?

Mickaël

1 Like

Hi

  • Do you want your .ts files to be analysed, or only the resulted js after the compilation?
    We want the .ts files to be analysed, because the resulted js is generated and outside our influence.

  • Are you sure that the file you want to analyse are well checkout on the file system where your agent is located ?
    Yes, the ts files are checkout in the source folder on the Azure DevOps Hosted Agent, but are not touched in the MSBuild step.

Youri

Hi,

It should be working, as long as your ts files are correctly embedded in your solution (i guess)

Do you have some kind of logs in your Run Analysis task logs ? (at least the Sonar TS sensor being triggered)

Thanks,

@DVB,

Currently the Scanner for MSBuild only analyzes files that are referenced by an MSBuild project.

You have two options for analyzing your TypeScript files:

A) analyze them separately using the scanner-cli as described in the SonarTS page. Note that you would have to send the results to a different SonarCloud project; if you use the same project key for a scanner-cli analysis and a Scanner for MSBuild analysis then the results will overwrite each other.

or

B) reference the TypeScript files from an MSBuild project that is built as part of the solution.
This could either be an existing project, or a dummy MSBuild project that exists just to hook into the Scanner for MSBuild.
Referencing the files to be analysed from an existing solution is the easier option and you could do it by adding something like the following to one of your projects:

  <ItemGroup>
    <!-- Additional files we want to be analyzed by the Scanner for MSBuild -->
    <!-- Note: setting Visible to false isn't required but stops the files from appearing
         in the Solution Explorer in VS -->
    <None Include="..\SharedTs\**\*.ts" Visible="False" />
  </ItemGroup>

Creating a dummy project is more complicated as you need to configure some other settings in the project to make it work correctly with the Scanner for MSBuild. There are some pointers on how to do this StackOverflow answer.

We’d like to make this scenario easier to do and have some tickets in the backlog e.g. #443.

3 Likes

Thanks @duncanp. This helped me a lot and also solved scanning of scss files.

A side note: On your documentation pages you link to SonarTS. The GitHub project state that the analyzer is legacy and TypeScript analysis for SonarQube was migrated to SonarJS plugin. Maybe you need to update your docu?