Skip to content

Add a new command line switch to skip analyzer execution - #46669

Merged
3 commits merged into
dotnet:masterfrom
mavasani:AddSkipAnalyzersSwitch
Aug 10, 2020
Merged

3 commits merged into
dotnet:masterfrom
mavasani:AddSkipAnalyzersSwitch

Conversation

@mavasani

Copy link
Copy Markdown
Contributor

Fixes #40926

This support was added to Microsoft.CodeAnalysis.targets (ships with VS) in VS2019 16.5:
https://docs.microsoft.com/en-us/visualstudio/code-quality/disable-code-analysis?view=vs-2019.

However, the MSBuild property is not respected from 'dotnet' builds where this targets file is not imported (see #40926 (comment) for details).

This change moves the skip analyzers logic down to Microsoft.Managed.Core.targets and core compiler layer so it is respected for all builds. As per offline discussions with Jared and Chris, we can no longer skip analyzer execution from MSBuild by removing the "Analyzer" items as these can include source generators, which should never be skipped (at least there are no current scenarios where we want to skip generators). Hence, we are adding a new command line compiler switch /skipAnalyzers, optionally followed by a + or -, to allow skipping analyzers.

I verified the end-to-end functionality works fine by locally building Microsoft.Net.Compilers.Toolset.Package NuGet package and referencing it in a project.

Fixes dotnet#40926

This support was added to `Microsoft.CodeAnalysis.targets` (ships with VS) in VS2019 16.5:
https://docs.microsoft.com/en-us/visualstudio/code-quality/disable-code-analysis?view=vs-2019.

However, the MSBuild property is not respected from 'dotnet' builds where this targets file is not imported (see dotnet#40926 (comment) for details).

This change moves the skip analyzers logic down to `Microsoft.Managed.Core.targets` and core compiler layer so it is respected for all builds. As per offline discussions with Jared and Chris, we can no longer skip analyzer execution from MSBuild by removing the "Analyzer" items as these can include source generators, which should never be skipped (at least there are no current scenarios where we want to skip generators). Hence, we are adding a new command line compiler switch `/skipAnalyzers`, optionally followed by a `+` or `-`, to allow skipping analyzers.

I verified the end-to-end functionality works fine by locally building `Microsoft.Net.Compilers.Toolset.Package` NuGet package and referencing it in a project.
@chsienki

Copy link
Copy Markdown
Member

@chsienki is added to the review. #Closed

@chsienki chsienki left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

</Target>

<Target Name="_ComputeSkipAnalyzers" BeforeTargets="CoreCompile">
<!-- First, force clear non-user facing property '_SkipAnalyzers'. -->

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trust no one ;)

image

@mavasani

Copy link
Copy Markdown
Contributor Author

Thanks for the quick reviews!

@ghost

ghost commented Aug 10, 2020

Copy link
Copy Markdown

Hello @mavasani!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-approval

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MSBuild parameter -p:RunAnalyzers=false is ignored

4 participants