Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

visual studio - How to check all projects in solution for some criteria?

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

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.

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 :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...