Visual Studio Check In Policy in combination with .NET analyzers

173 views Asked by At

We worked before with FxCop Code Analyzers and TFS check in policies. I can find articles to migrate the code analysis to .Net Analyzer. I changed a project and the code analysis seems to be working after removing the deprecated FxCop.

But I cannot find any information regarding changing the check in policies to match with the new .NET Analyzers. Does anyone have information on this topic?

.csproj true

<AnalysisLevel>none</AnalysisLevel>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<RunCodeAnalysis>false</RunCodeAnalysis>

Instead of a ruleset .NetAnalyzers seem to use "Analysis Level" which can not be configured in the checkin policies.

VS Project Settings and Source Control Settings

Build is working fine without errors and we get warnings due to code analysis. We tried to add a Code Ruleset in the project for the MinimumRecommendedRules.ruleset but when we check in get:

An unexpected error occurred while evaluating the Code Analysis check-in policy. The error might be transient. Try again.

1

There are 1 answers

0
BudBrot On BEST ANSWER

Apparently, it is not possible to use both features together.

The Check-In-Policy checks (among other things) whether the <RunCodeAnalysis>-msbuild setting is set to true.

enter image description here

Anyways, this setting forces the legacy binary analysis to run.

Reference (from Microsoft Docs):

Does the RunCodeAnalysis msbuild project property run analyzers? No. The RunCodeAnalysis property in a project file (for example, .csproj) is only used to execute legacy FxCop. It runs a post-build msbuild task that invokes FxCopCmd.exe.

I think it should not be needed to have a seperate check-in policys anymore, as the .NET analyzers run on every (release, depending on your configuration) build.