RunCodeAnalysis=true not working in command prompt (MSBuild)
Asked Answered
K

3

10

I'm trying to get msbuild to output code analysis info like it does in VS. I have a configuration for my project called "CodeAnalysis" in VS that is set up to run code analysis on build (with the minimum ruleset). Anyway this is working fine in VS, but when I run msbuild from the command line it only shows the basic build warnings and it doesn't run code analysis at all. Anyone know why this is happening?

Configuration in project file:

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'CodeAnalysis|AnyCPU'">
<OutputPath>bin\</OutputPath>
<CodeAnalysisRuleSet>C:\Program Files\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\Rule Sets\MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<RunCodeAnalysis>true</RunCodeAnalysis>

Command line:

msbuild Solution.sln /p:Configuration=CodeAnalysis /t:Rebuild

I also tried:

msbuild Solution.sln /p:RunCodeAnalysis=true /t:Rebuild
Kevon answered 18/10, 2011 at 13:46 Comment(6)
run with diagnostic level logging (/fl /flp:v=diag;logfile=diag.log) and search for why the RunCodeAnalysis target is being skipped. It should be run as a dependency of PrepareForRun which is run as a dependency of CoreBuild.Swathe
Check whether properties $(CodeAnalysisPath), $(CodeAnalysisTargets) already set and referencing the valid code analysis tooling path, basically just print them out inside a scriptEndocentric
@BrianKretzler Thanks for the tip. Is there something in particular I should be looking for? I found the following: CoreBuildDependsOn = PrepareForRun; PrepareForRunDependsOn = RunCodeAnalysis; I also noticed that at the corebuild action it says: Task "CallTarget" skipped, due to false condition; ('$(UnloadProjectsOnCompletion)'=='true') was evaluated as ('false'=='true').....could this be related?Kevon
@Endocentric CodeAnalysisPath was not correctly set to the directory of FxCop. Setting it solved my problem. Only problem now is that it outputs ~3000 warnings instead of the ~200 when using VS. I have the ruleset defined (CodeAnalysisRuleSet is set correctly). Any ideas? Thank you both for your help so far.Kevon
Does your output path contain both your own assemblies and the "copy local" referenced assemblies of your projects? If so, it might be running on all of themShandy
The answer to [How to force MSBuild to run Code Analysis without recompiling][1] may be the answer to your question as well. [1]: #26035058Transfinite
F
9

By default, MSBuild uses the value configured in the project file, but you can override it on the msbuild command-line using the argument

/p:RunCodeAnalysis=true

to always run code analysis. Vice versa, use

/p:RunCodeAnalysis=false

to disable code analysis.

See also:

Flunk answered 8/1, 2013 at 16:21 Comment(1)
Always and Never are the values presented by the XAML build configuration, but under the hood they're translated to true and false when passed to MsBuild.Shandy
C
1

You need to have Visual Studio installed on the machine. There are many scripts that are included via csproj line:

As you have VS (of proper edition) installed it will include FxCop targets file and will start Code Analysis for you.

Candlemaker answered 19/3, 2012 at 12:46 Comment(2)
As I understand it FxCop analysis and Visual Studio Code Analysis are not the same.Diverge
They are the same thing. Code Analysis just has more rules now and with 2015 it also supports Roslyn Analyzers. fxCop will never support those.Shandy
F
0

Once I faced the same problem, I started by getting a (overly) verbose log and piped it to a file that I could inspect:

msbuild.exe ProjectFile.csproj /v:diag > bld.log

In that file, I noticed that the Code Analysis target was skipped because RunCodeAnalysisOnThisProject was evaluated to true. So in the csproj, I included the following line under the first property group:

<RunCodeAnalysisOnThisProject>true</RunCodeAnalysisOnThisProject>

which did it for me.

Fetich answered 29/6, 2016 at 11:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.