Programatic build events in C#?
This sounds like fantasy to me but can I make a class in my project开发者_如何学Go that runs methods or something like that when the project is built? Is there an interface or abstract class for that?
Your project files are made up of MSBuild files, you can execute pretty much anything from them:
http://msdn.microsoft.com/en-us/library/7z253716.aspx
Basically you can 'unload' the project file in Visual Studio and edit them with a normal text editor.
Look for this area in your *.csproj files (and some other project types, note that not all project files are MSBuild compatible files):
<!-- 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>
-->
And just add your MSBuild tasks there :)
As Zidad pointed out, you can edit the MSBuild project file itself.
You can also just add some stuff in your PreBuild
and PostBuild
events. Check the project properties pane.
I think you need to program MSBuild Tasks. If you want better personalization, you can create someting like a batch or if you want a console or winform application and invoke command line msbuild and do things programatically.
MSBuild has the ability to use custom Tasks, derived from the Task class. Which lets you create custom tasks and hook them into various points as the build progresses.
But it sounds almost like you want something to take actions as the code is compiling, which obviously is impossible because the code isn't compiled yet.
精彩评论