No tsconfig.json file found using .NET scanner

When using sonarscanner for .NET version 6.2.0 to analyze a C# .NET project, containing multiple TypeSycript files, the sonarscanner does not analyze any TypeScript content.

Taking a look into the debug logs, I see that the scanner doesn’t detect any tsconfig.json files. To be fair, the (multiple) tsconfig files are located in a subdirectory of the root folder, but setting the path to said files manually also doesn’t change that fact.

I even created a tsconfig file in the root folder of the project, containing universal dummy content like

{ "include": ["**/*.ts", "**/*.tsx"] }

but it still doesn’t recognize any tsconfig files.

The logs keep saying:

14:55:42.800 INFO: Resolving TSConfig files using 'tsconfig.json' from property sonar.typescript.tsconfigPath 
14:55:42.800 DEBUG: Using 'tsconfig.json' to resolve TSConfig file(s) 
14:55:42.808 INFO: Found 0 TSConfig file(s): [] 
14:55:42.813 INFO: Found 0 tsconfig.json file(s): [] 
14:55:42.814 INFO: No tsconfig.json file found

What else could I be missing here?

Hi,

Welcome to the community!

I think these docs may be relevant:

the SonarScanner for .NET will analyze all file types that are supported by the project type (for example, esproj), MSBuild, and the available language plugins unless explicitly excluded.

If you have an esproj project type, make sure to use Microsoft.VisualStudio.JavaScript.SDK version 0.5.74-alpha or later to ensure the SonarScanner for .NET recognizes the esproj contents for scanning.

 
HTH,
Ann

Thank you very much for your reply!

The project(s) in the analyzed solution isn’t (aren’t) a .esproj, so that shouldn’t be problematic.

Furthermore, i see no entry in our .csproj that would specifically exclude tsconfig files. Also, I’ve explicitly added them with

  <ItemGroup>
    <Content Include="**/tsconfig.json" />
  </ItemGroup>

as the last entry of the file.

Shouldn’t that enable their detection - no matter what?

I’ve also taken a look into the .sonarqube\out\sonar-project.properties file. The tsconfigs as well as the .ts files are listed as sources there. Nevertheless they aren’t getting analyzed.

Hi,

Could you provide full debug job logs?

Share the Scanner for .NET verbose logs

  • Add /d:"sonar.verbose=true" to the…
    • SonarScanner.MSBuild.exe or dotnet sonarscanner begin command to get more detailed logs
      • For example: SonarScanner.MSBuild.exe begin /k:"MyProject" /d:"sonar.verbose=true"
    • “SonarQubePrepare” or “SonarCloudPrepare” task’s extraProperties argument if you are using Azure DevOps
      • For example:
        - task: SonarCloudPrepare@1
            inputs:
              SonarCloud: 'sonarcloud'
              organization: 'foo'
              scannerMode: 'MSBuild'
              projectKey: 'foo_sonar-scanning-someconsoleapp'
              projectName: 'sonar-scanning-someconsoleapp'
              extraProperties: |
                sonar.verbose=true
        
  • The important logs are in the END step (i.e. SonarQubeAnalyze / SonarCloudAnalyze / “Run Code Analysis”)

Share the msbuild detailed logs

MsBuild.exe /t:Rebuild /v:d

or

dotnet build -v:d

 
Thx,
Ann

Hi, I have taken your advice and logged with verbose set to true, resulting in very detailed logs. Thank you very much for that hint.

Unfortunately, I cannot post full logs (due to them containing a lot of sensitive data, and being way too long to properly redact and reduce them), but I’ve gathered some more insight into the problem thanks to these logs:

As it seems, the problem is not (as I initially expected) that SonarQube isn’t picking up tsconfig files. Our solution consists of many projects, sometimes nested into each other.

We have a project on the very first level. Let’s call this project “Web”. In Web, there is a tsconfig file, as well as several sub projects (let’s say “Web.A”, “Web.B”, “Web.C” and so on). These sub projects do not contain tsconfig files, but they do contain ts files. Naturally, SonarQube doesn’t detect tsconfig files for these projects.

Unfortunately, the analysis of these sub-projects (or modules, as they’re called in the SonarQube logs) happens before the analysis of the Web project, leading to them being logged first. That’s the reason why I assumed no tsconfig file being found is the problem. However: It isn’t.

The tsconfig file of the Web project gets detected properly and SonarQube interprets it’s contents correctly. But here’s the real reason why the ts files in question are not being analysed: They don’t get counted as a part of the Web project (which in fact they really aren’t. They are part of the sub-project they belong to.). So the logs print File not part of the project for every single one of them, when analyzing the Web project.

On the other hand, in the analysis of a sub-project (to which the ts files belong), there is no tsconfig. Hence, SonarQube is (again) skipping the analysis of the ts file.

What would be the best approach to resolve this problem of “one of the two conditions always missing”?

Hi,

Would you be willing to share the logs privately?

 
Ann

Sure thing! Drop me an email adress or a Signal ID or something and I’ll send them over tomorrow.
Thank you very much, I really appreciate your help :slight_smile:

Hi,

I’ve referred this to the experts. They’ll contact you for logs.

 
Ann

1 Like

Hello @SamuelBlickle,

I’ve contacted you regarding the logs.

Best Regards
Mary