RunCodeAnalysis=true 在命令提示符下不起作用 (MSBuild)
我试图让 msbuild 输出代码分析信息,就像在 VS 中一样。我在 VS 中有一个名为“CodeAnalysis”的项目配置,它被设置为在构建时运行代码分析(使用最小规则集)。不管怎样,这在 VS 中工作得很好,但是当我从命令行运行 msbuild 时,它只显示基本的构建警告,并且根本不运行代码分析。有谁知道为什么会发生这种情况?
项目文件中的配置:
<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>
命令行:
msbuild Solution.sln /p:Configuration=CodeAnalysis /t:Rebuild
我也尝试过:
msbuild Solution.sln /p:RunCodeAnalysis=true /t:Rebuild
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
默认情况下,MSBuild 使用项目文件中配置的值,但您可以使用参数在
msbuild
命令行上覆盖它,以始终运行代码分析。反之亦然,用于
禁用代码分析。
另请参阅:
By default, MSBuild uses the value configured in the project file, but you can override it on the
msbuild
command-line using the argumentto always run code analysis. Vice versa, use
to disable code analysis.
See also:
您需要在计算机上安装 Visual Studio。通过 csproj 行包含许多脚本:
当您安装了 VS(正确版本)时,它将包含 FxCop 目标文件,并将为您启动代码分析。
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.
一旦我遇到同样的问题,我首先获取一个(过于)详细的日志并将其通过管道传输到一个我可以检查的文件:
在该文件中,我注意到代码分析目标被跳过,因为 RunCodeAnalysisOnThisProject 被评估为 true。因此,在 csproj 中,我在第一个属性组下包含了以下行:
这为我完成了。
Once I faced the same problem, I started by getting a (overly) verbose log and piped it to a file that I could inspect:
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:
which did it for me.