Search code examples
c#sonarlintsonarlint-vs

Disable SonarLint analysis during Debug build


Is it possible (in Visual Studio using SonarLint extension) to disable Sonar Analyzers during Debug build, but keep them enabled in Release build? The reason is that connecting the solution to SonarQube has drastically increased the build time.


Solution

  • I ended up modifying the .csproj files to remove the analyzers if I'm building the solution from within Visual Studio in Debug configuration. That way, sonarlint does not complain that rules are outdated, nor does it get affected by updates. I got the answer from here

    <Target Name="DisableAnalyzersForVisualStudioBuild"
            BeforeTargets="CoreCompile"
            Condition="'$(BuildingInsideVisualStudio)' == 'True' And '$(BuildingProject)' == 'True' And '$(Configuration)' == 'Debug'">
      <!--
        Disable analyzers when building a project inside Visual Studio. Note that analyzer behavior for IntelliSense purposes is not altered by this.
      -->
      <ItemGroup>
        <Analyzer Remove="@(Analyzer)"/>
      </ItemGroup>
    </Target>