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

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

问题描述

我需要让解决方案中的所有项目都包含一些其他的构建操作,例如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)如果无法实现,请在"解决方案范围内的构建事件?".它很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.也欢迎解决整个问题的任何其他选择:)

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

推荐答案

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

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天全站免登陆