Vercas
Vercas

Reputation: 9161

Programatic build events in C#?

This sounds like fantasy to me but can I make a class in my project that runs methods or something like that when the project is built? Is there an interface or abstract class for that?

Upvotes: 1

Views: 450

Answers (4)

Wiebe Tijsma
Wiebe Tijsma

Reputation: 10275

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

Upvotes: 5

jmanuelcorral
jmanuelcorral

Reputation: 21

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.

Upvotes: 1

Daren Thomas
Daren Thomas

Reputation: 70354

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.

Upvotes: 1

Massif
Massif

Reputation: 4433

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.

Upvotes: 0

Related Questions