是否可以在 Visual Studio 2013 中完成整个编译时运行生成后事件



我有一个包含多个项目的解决方案,我们使用FxCop。我们希望在编译请求完成后运行它(它可能是一个项目、一个包含多个文件夹的文件夹或整个解决方案)。

有没有办法做到这一点?我们目前每个项目都这样做,但这有一些缺点。

是的,有一种方法可以通过在具有特定命名模式的解决方案文件旁边放置一个文件来做到这一点:after.{Your solution name here}.sln.targets

<!--?xml version="1.0" encoding="utf-8"?-->
<project toolsversion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <target name="AtTheStart" beforetargets="Build">
    <message text="GenerateCode target running" importance="high">
    </message>
  </target>
  <target name="AtTheEnd" aftertargets="Build">
    <message text="GenerateCode target running" importance="high">
    </message>
  </target>
</project>

但是,如果您想有效地运行 FxCop 并安装可视化工作室,您实际上可以在构建期间通过在对 MsBuild 的调用中包含/p:RunCodeAnalysis=true/p:RunCodeAnalysis=always来激活它。这将在构建期间运行配置的规则集文件。 /p:CodeAnalysisRuleSet=PathTo.ruleset将允许您指定特定的规则集文件。

命令行将始终覆盖项目自己的配置。它将以最佳方式运行。

我会放置 FxCop 项目集(所有项目中的所有 dll)并在所有项目在 VS 中构建后调用它。

最新更新