C# code not analized

It analyses JavaScript, CSS and other code from our repo but looks like it’s skipping C# for some reason. Let me know if you need some more info?

1 Like

We’re facing the same issue and would like to see if there is any support available on this.

Hi,

When you import your repo into SonarCloud it automatically determines whether it is eligible for automatic analysis by detecting which language is predominant.

In your case it seems that the majority of your code is JS or CSS so the system proceeds to do automatic analysis. Automatic analysis is a process where SonarCloud analyzes your code directly from the repo in which it resides. See https://sonarcloud.io/documentation/advanced-setup/automatic-analysis/

But, automatic analysis only applies to a subset of languages, which does not include C#.

To do C# analysis you need to set up CI-based analysis. In CI-based analysis you have to configure your build process to perform the analysis locally (or in your Cloud CI environment). For C# you would use a tool called the SonarScanner for .NET. See https://sonarcloud.io/documentation/advanced-setup/ci-based-analysis/overview/

To analyze both JS and C# in the same repo presents a bit of a challenge. One solution might be to do the JS analysis via AA while setting up a different manually created project in SC for the C# analysis. You would then configure your CI-based analysis to connect with that second manually created project in SC.

Thanks for the advice @Peeter_Piegaze, I really appreciate it.

Yes, we use Pipeline from Bitbucket. I also tried setting up one separate (manual) project for C# purpose. This is how our step in bitbucket-pipeline looks like:

        - step:
            name: SonarCloudCS
            size: 2x
            image: mcr.microsoft.com/dotnet/sdk:3.1
            caches:
              - sonar
              - docker
            script:
              - apt-get update
              - apt-get install -y default-jre
              - export PATH=${PATH}:${HOME}/.dotnet/tools
              - dotnet tool install --global dotnet-sonarscanner --version 5.2.2
              - dotnet sonarscanner begin /o:"myOrg" /k:"myOrg_SomeKey" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login=${SONAR_TOKEN}
              - dotnet build ./Path/To/My/Project.csproj
              - dotnet sonarscanner end /d:sonar.login=${SONAR_TOKEN}
              - pipe: sonarsource/sonarcloud-scan:1.2.1
            services:
              - docker

At the moment it still ignores C# code