RunCodeAnalysis=true 在命令提示符下不起作用 (MSBuild)

发布于 2024-12-10 16:49:19 字数 786 浏览 0 评论 0原文

我试图让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

此生挚爱伱 2024-12-17 16:49:19

默认情况下,MSBuild 使用项目文件中配置的值,但您可以使用参数在 msbuild 命令行上覆盖它,

/p:RunCodeAnalysis=true

以始终运行代码分析。反之亦然,用于

/p:RunCodeAnalysis=false

禁用代码分析。

另请参阅:

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:

北风几吹夏 2024-12-17 16:49:19

您需要在计算机上安装 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.

↘人皮目录ツ 2024-12-17 16:49:19

一旦我遇到同样的问题,我首先获取一个(过于)详细的日志并将其通过管道传输到一个我可以检查的文件:

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

在该文件中,我注意到代码分析目标被跳过,因为 RunCodeAnalysisOnThisProject 被评估为 true。因此,在 csproj 中,我在第一个属性组下包含了以下行:

<RunCodeAnalysisOnThisProject>true</RunCodeAnalysisOnThisProject>

这为我完成了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文