StyleCop MS建立魔术?谁称呼StyleCop目标? [英] StyleCop MS Build magic? Who is calling the StyleCop target?

查看:86
本文介绍了StyleCop MS建立魔术?谁称呼StyleCop目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的项目文件中,我们使用StyleCop并在构建过程中运行它.我们已经修改了项目文件,使其包含StyleCop目标,如下所示:

In our project files we are using StyleCop and are running it during the build process. We've modified our project files to include the StyleCop targets like so:

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />
<Import Project="..\..\Tools\Microsoft\StyleCop\v4.3\Microsoft.StyleCop.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
     Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->

问题是为什么这行得通?谁在调用Microsoft.StyleCop.targets文件中定义的StyleCop目标?

The question is why does this work? Who is calling the StyleCop target defined in the Microsoft.StyleCop.targets file?

据我所知,开始构建时运行的唯一目标是"Build"目标.我在Microsoft.StyleCop.targets文件之外的任何地方都找不到对"StyleCop"目标的引用.再说一遍,为什么叫它?

As far as I can tell, the only target being run when you start the build, is the "Build" target. I can't find any references to the "StyleCop" target anywhere outside the Microsoft.StyleCop.targets file. So again, why is it being called?

我想知道的原因是,如果我们可以为自己的自定义任务做类似的事情,那将会很酷.因此,我们不必编辑我们所有的78个csproj文件,而只需导入自己的一般目标,例如:

The reason I want to know is because it would be cool if we could do something similar for our own custom tasks. So instead of editing all of our 78 csproj files, we could just import our own general target like:

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />
<Import Project="Common.targets" />

然后将StyleCop以及我们需要在每个项目中完成的所有其他任务一起导入该文件中.

And then just import StyleCop in that file instead, along with all our other tasks that need to be done on a per project basis.

请帮助我理解.

推荐答案

尤里卡!

秘密调味料是StyleCop目标文件中的以下几行:

The secret sauce is the following lines in the StyleCop targets file:

<PropertyGroup>
  <BuildDependsOn>$(BuildDependsOn);StyleCop</BuildDependsOn>
  <RebuildDependsOn>StyleCopForceFullAnalysis;$(RebuildDependsOn)</RebuildDependsOn>
</PropertyGroup>

Microsoft.Common.targets中的"Build"目标声明如下:

The "Build" target in Microsoft.Common.targets is declared like so:

<Target Name="Build"
        Condition=" '$(_InvalidConfigurationWarning)' != 'true' "
        DependsOnTargets="$(BuildDependsOn)"
        Outputs="$(TargetPath)" />

这意味着在构建过程中将调用"BuildDependsOn"属性中列出的任何目标.那不是很好吗? :)

This means that any target listed in the "BuildDependsOn" property will get called during the build. Isn't that nice? :)

这篇关于StyleCop MS建立魔术?谁称呼StyleCop目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆