Unable to use SonarLint in Visual Studio for a non-CMake C++ project

Background info:

  • Operating system: Windows 11 Pro
  • Visual Studio version: Microsoft Visual Studio Enterprise 2022 (64-bit) Version 17.6.5
  • SonarLint plugin version:
  • Programming language you’re coding in: C++ 14 compiled with Visual Studio
  • Is connected mode used: Yes
    • Connected to SonarCloud or SonarQube (and which version): SonarQube Developer Edition Version 10.1 (build 73491)

And a thorough description of the problem / question:

We have a working pipeline of SonarQube running on an in-house server, providing Pull Request decorations into BitBucket, and the analysis is working nicely with our C++ project. However, now we would like to use SonarLint with Visual Studio on our developers’ workstations, but unfortunately our project configuration does not seem to be supported by SonarLint. Here’s what SonarLint prints in Visual Studio’s Output window when I open a file, and SonarLint attempts to analyze it:

[ThreadId 22] [DEBUG] [VCX:VcxRequestFactory] [Thread id: 22] Trying to create request for REDACTED_FILEPATH\REDACTED_FILENAME.cxx
[ThreadId 1] [DEBUG] [VCX:VcxRequestFactory] [Thread id: 1]     Could not get the file configuration
[ThreadId 72] [DEBUG] [CompilationDatabaseLocator] Could not find project root directory
[ThreadId 22] [DEBUG] [ExclusionSettingsStorage] File content: {
  "sonar.exclusions": [],
  "sonar.global.exclusions": [],
  "sonar.inclusions": []
[ThreadId 22] [DEBUG] [AnalyzableFileIndicator]
  Server Exclusions: 
    Global Exclusions: 
  should analyze: True 
[ThreadId 22] [SecretsAnalyzer] Analyzing REDACTED_FILEPATH\REDACTED_FILENAME.cxx
[ThreadId 22] Loaded settings from "REDACTED_FILEPATH\AppData\Roaming\SonarLint for Visual Studio\Bindings\REDACTED_SOLUTION_NAME\secrets_settings.json".
[ThreadId 22] [RuleSettings] Using connected mode settings. User-specified settings in settings.json will be ignored.
[ThreadId 22] [SecretsAnalyzer] Finished analyzing REDACTED_FILEPATH\REDACTED_FILENAME.cxx, analysis time: 0.047s
[ThreadId 22] [SecretsAnalyzer] Found 0 issue(s) for REDACTED_FILEPATH\REDACTED_FILENAME.cxx
[ThreadId 22] [DEBUG] [VCX:VcxRequestFactory] [Thread id: 22] Trying to create request for REDACTED_FILEPATH\REDACTED_FILENAME.cxx
[ThreadId 1] Project's "Configuration type" is not supported.
[ThreadId 1] [DEBUG] [VCX:VcxRequestFactory] [Thread id: 1]     Could not get the file configuration
[ThreadId 90] [DEBUG] [CompilationDatabaseLocator] Could not find project root directory
[ThreadId 90] Unable to retrieve the configuration for file 'REDACTED_FILEPATH\REDACTED_FILENAME.cxx'.
    Check the file is part of a supported project type in the current solution.

Thus we do not get any results from SonarLint. Our C++ project does NOT use CMake, and thus our build does not use a “compilation database” or “compile_commands.json” file. To try and circumvent this, we created a mock “compilation database” file for SonarLint to use. Unfortunately, this does not seem sufficient for SonarLint’s requirements. Looking through the SonarLint Visual Studio extension’s source code, it seems that only projects opened in “folder workspace mode” are supported, and this is not how our solution/project is set up.

We tried to see whether we could build the SonarLint extension from source, to modify the source code to skip the check for the “folder workspace mode”. However, is seems that it is no longer an option, due to problems with JFrog on your end (see possibly related forum post from this spring), preventing us from building SonarLint’s Visual Studio extension from the source code.

In summary, here’s what we would like to know:

  1. Is it possible to use SonarLint with a C++ project that does not use CMake?
  2. If not, how can we build SonarLint from source (to modify this part of its code) without access to your JFrog instance?

Thanks in advance!

Hey @ArttuHalonen

Are you using the vcxproj & VS solution format or something else completely?

Yes, our project has a .sln file and a .vcxproj file.

When in folder mode, we assume it’s CMake, so you would need to use the solution mode instead. Press the Open a project or solution option on the VS startup page and select the .sln file.

Actually, I think the problem is not with CMake, but with your vcxproj. It fails to get recognized by our extension. The CMake logs are there because the initial attempt with vcxproj failed.

The log line Project's "Configuration type" is not supported. is produced when we get ConfigurationTypes.typeUnknown from Microsoft.VisualStudio.VCProjectEngine

Are you using a special project type?

We always use the solution mode in Visual Studio, as we have a .sln file.

Our project’s configuration type in the .vcxproj file is <ConfigurationType>Makefile</ConfigurationType>, which, I assume, corresponds with typeGeneric 10 Makefile in the VCProjectEngine article you linked. Our project utilizes NMAKE as the makefile tool.

Could you please provide a stripped-down reproducer solution for the problem?
Currently, we don’t have enough data to investigate this, as the VisualStudio APIs are giving us the typeUnknown, according to the logs, which causes the problem.

Please find the attached barebones Visual Studio solution to reproduce the issue. Our build system is naturally more complex, but this is enough to showcase the issue.
SonarLintErrorReproduction.zip (3.6 KB)

You can also reproduce the issue yourself by following these steps:

  1. Create a new “Makefile project” in Visual Studio (SonarLintErrorReproduction.sln)
  2. Add any .cxx file (Dummy.cxx)
  3. Open the .cxx file and look at the SonarLint output
1 Like

@ArttuHalonen Unfortunately, our documentation (both public and internal) is lacking in this aspect, and we don’t currently support the Makefile variant of vcxproj in SonarLint for VisualStudio. I will also forward the feedback regarding missing support for Makefile to the Product Management team.

Apologies for not being able to provide a solution to your problem.

Ok, thanks for looking into this! Let’s hope that the issue will be resolved soon.

In the meantime, we would like to investigate a potential workaround by compiling the SonarLint Visual Studio extension ourselves from the source code, which is publicly available. However, it seems that it is currently impossible, due to the compilation process requiring credentials to JFrog for some build artifacts. How could we access these, in order to compile SonarLint ourselves from source?

Hey. Sorry for the late reply. I was on holiday.

I don’t think you can easily fix your problem. The folder mode check comes after the solution mode check, so there’s no need to disable it if the solution mode works correctly. The problem with solution mode is that the Configuration type returned by VCProjectEngine is, for some reason, typeUnknown. I tried to remove the check (type != typeUnknown) and see how it proceeds. The project engine API fails with an exception when trying to retrieve the configuration. There probably is a way to support makefile projects, but it would require more than just removing some checks in the existing code.

Regarding the Repox: we’re currently in a transition process with our package management. While you could checkout the last release’s commit and just remove repox from nuget.config, there’s a chance the other nuget feed will be disabled soon, and some packages will only be available via repox. In the future, we have a plan to get rid of repox too, but the timeline is uncertain for now.