Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scanner should override RunAnalyzers/RunAnalyzersDuringBuild properties #829

Closed
duncanp-sonar opened this issue Jan 31, 2020 · 2 comments · Fixed by #993
Closed

Scanner should override RunAnalyzers/RunAnalyzersDuringBuild properties #829

duncanp-sonar opened this issue Jan 31, 2020 · 2 comments · Fixed by #993
Assignees
Milestone

Comments

@duncanp-sonar
Copy link
Contributor

duncanp-sonar commented Jan 31, 2020

Description

VS2019 and the corresponding MSBuild targets now supports project-file properties to control whether NuGet analyzers are executed. See here.

The scanner should override those properties at build time to that analysis always performed, regardless of the properties that are set in the project file.

Note: the SonarQube.Integration.targets already contain a target called SetRoslynCodeAnalysisProperties that sets some of the analysis properties at build time.

User impact: the current behaviour can lead to hard-to-diagnose issues. See this community thread.

TODO

Decide what the user behaviour we actually want in this case.

On the one, if the user has set RunAnalyzers/RunAnalyzersDuringBuild=false, they might expect that the project would be skipped by Sonar analysis too.
On the other hand, if the user has triggered an analysis run using the Scanner for MSBuild, they probably expect everything to be analyzed.

Repro steps

  1. Edit a project to contain the following XML:
  <PropertyGroup>
    <RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
  </PropertyGroup>
  1. Run the scanner begin step
  2. Build the project

Expected behavior

SonarC#/VB.NET analysis rules are executed and metrics are produced.

Actual behavior

The build completes successfully, but the SonarC#/VB.NET analysis rules are not executed and no metrics are produced.

Note: no analysis results are pushed to the server. If the project has not been analysed before then the Sonar UI will say The main branch of this project is empty.

Known workarounds

Don't manually set RunAnalyzers or RunAnalyzerDuringBuild to false.

Related information

  • MSBuild: v16.3+
  • SonarScanner for MSBuild version: latest
  • SonarQube server version: n/a
  • Languages in your solution: C#, VB.Net
@santhonisz
Copy link

For what it's worth, we just encountered this issue and the relatively simple work-around was to supply the /p:RunAnalyzers=true argument when running the msbuild command to build the project.

@pavel-mikula-sonarsource pavel-mikula-sonarsource added this to To do in S4NET Kanban via automation Mar 24, 2021
@pavel-mikula-sonarsource pavel-mikula-sonarsource added this to the 5.2.0 milestone Mar 24, 2021
@pavel-mikula-sonarsource
Copy link
Contributor

We just experience the same issue ourselves.

Scenario: We need to speed up local build (by excluding analysis) when a test is executed from VS UI while still keeping the CI and build setup running the analysis.

Let's just override the setting as we do for the other properties. If users don't want the project to be analyzed, they should set SonarQubeExclude=true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
S4NET Kanban
  
Done
4 participants