如何根据某些标准检查解决方案中的所有项目? [英] How to check all projects in solution for some criteria?

查看:15
本文介绍了如何根据某些标准检查解决方案中的所有项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要让解决方案中的所有项目都包含一些额外的构建操作,例如StyleCop 验证、AssemblyInfo 的自动生成等.

I need to let all projects in solution contain some additional build actions, e.g. StyleCop validation, autogenaration of AssemblyInfo's, etc.

我的想法是进行某种解决方案范围的预构建事件,该事件将检查所有项目文件中是否包含与特定 xPath 匹配的节点.这不是一个难点,它可以通过自定义构建任务或一些第三方 Xml 处理任务来解决.我还没有深入研究它,但它绝对不会成为值得在这里提及的问题.

My idea is to make some kind of solution-wide prebuild event that will check all project files for containing nodes that match specific xPath. It's not a hard part, it can be solved either with custom build task, or with some third-party Xml handling task. I didn't investigate it deeply yet, but it definitely won't make a problem worth mentioning here.

问题是如何
1)用一些自定义任务扩展解决方案文件?它不应该是解决方案的必要组成部分.这是需要的,但在从 VS 构建时可以省略,有一些特定的命令行来执行它就足够了.
2)如果不可能,Solution-wide pre-中描述的选项构建事件?".它很hacky,但如果没有其他选择,我会使用它.但是如何从解决方案文件中获取项目文件列表?请考虑到包含解决方案的文件夹可能包含不应检查的额外项目文件,因此仅枚举所有 ***.*proj 不是一个选项.

The questions are how to
1) extend solution file with some custom tasks? It shouldn't be necessary integral part of solution. It is desired, but can be omitted while building from VS, it will be enough to have some specific command line that executes it.
2) if its not possible, there is option described in "Solution-wide pre-build event?". It's hacky, but if there is no other options, I'll use it. But how to get list of project files from solution file? Please, take into account that folder that contains solution may contain extra project files that shouldn't be check, so just enumerate all ***.*proj is not an option.

附言也欢迎针对整个问题的任何其他选项:)

P.S. Any other options for entire problem are welcome too :)

推荐答案

您可以使用内置的 MSBuild 功能在任何条件下创建任何自定义任务来扩展功能:CustomAfterMicrosoftCommonTargetsCustomBeforeMicrosoftCommonTargets.

You can create any custom tasks with any conditions using built in MSBuild feature to extend functionality: CustomAfterMicrosoftCommonTargets, CustomBeforeMicrosoftCommonTargets.

查看我的 示例.您可以在 .targets 文件中为构建过程中的每个步骤添加自定义任务.您可以添加条件以打开/关闭这些操作等.它不依赖 sln 文件,但您可以使用条件 '$(BuildingInsideVisualStudio)'=='true' 执行特定于 VS 的任务.您可以从命令行调用它们 - 您需要使用键 /t:MyCustomTarget 指定目标名称.

See my example. You can add custom tasks in your .targets file for every step in build process. You can add conditions to turn on/off those actions and so on. It doesn't rely on sln file, but you can have tasks that will be VS-specific with condition '$(BuildingInsideVisualStudio)'=='true'. You can call them from command line - you need to specify the name of target with key /t:MyCustomTarget.

副作用:如果您的自定义目标没有任何特定条件 - 它将在每个类似项目中调用.

Sideeffects: if your custom target willn't have any specific conditions - it will be called in every similar project.

这篇关于如何根据某些标准检查解决方案中的所有项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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