How to force MSBuild to run Code Analysis without recompiling
Asked Answered
E

3

17

By default, code analysis is only done for projects which are compiled. So when I run MSBuild from the command line, it runs code analysis only for the first time. On subsequent calls, code analysis is skipped.

Background: I want to evaluate CA rules and see how many warnings there would be in our code when turning on a rule. For that I don't want to recompile everything - which takes some time - but just re-run the code analysis. How can you achieve this?

I am using Visual Studio 2013 and MSBuild 12.0.

Even explicitely switching on code analysis does not help:

msbuild DesktopBuild.proj /p:RunCodeAnalysis=true
Emperor answered 25/9, 2014 at 9:5 Comment(0)
E
16

It seems that

  1. del /s *.lastcodeanalysissucceeded
  2. msbuild DesktopBuild.proj /p:RunCodeAnalysis=true

seems to work. The first step causes code analysis to "forget" about the previous runs and the second step forces it to run for every project, even if code analysis is not enabled in a project. If running this repeatedly, the already compiled projects won't be compiled again, only the code analysis is re-run.

Emperor answered 26/9, 2014 at 15:56 Comment(1)
Hey, is there any way to do the 1st step in the XAML build definition without adding a separate batch file to the source control?Pore
G
6

Simply set CodeAnalysisGenerateSuccessFile to false in the project file.

<PropertyGroup>
  <RunCodeAnalysis>true</RunCodeAnalysis>
  <CodeAnalysisGenerateSuccessFile>false</CodeAnalysisGenerateSuccessFile>
</PropertyGroup>
Godric answered 9/8, 2017 at 23:5 Comment(0)
B
2

I would try using FxCopCmd.exe, it can be usually found in C:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\FxCop. It's used by CodeAnalysis in Visual Studio, you should be able to use it with proper parameters.

Batty answered 25/9, 2014 at 9:14 Comment(3)
The problem with this approach is that we have two different rule sets and each project defines which of those rule sets it uses. We have a few hundred projects, so how would I run FxCopCmd so that each project/DLL uses its configured rule set?Emperor
FxCopCmd has an option to set your own ruleset (/rs) or even to turn on and off specific rulesBatty
And how would that help me? As I wrote, there are a few hundred projects and I can not manually supply the ruleset for every assembly. That must happen automatically by using the .csproj file. And I think this is not possible with FxCopCmd.Emperor

© 2022 - 2024 — McMap. All rights reserved.