Can I add a custom "task" to the post-build event of multiple Visual Studio projects?

708 views Asked by At

I have a VS2010 solution with four projects in it.

I have a semi-complex command line that I want to run which uses Visual Studio build event macros.

This command line is currently in the post-build event of each project - however the command line is identical in each project, and I'd like to try to keep things DRY.

Is there a way to eliminate the repetition here, somehow setting up my command line, with macros, as a task somewhere and just call that task for each project?

1

There are 1 answers

0
Morvader On

I dont know if exists any way to link post-build events of different projects, but if you want to get the same effect you have to focus on having at all the .csproj files the same <PropertyGroup> tag, like this:

<PropertyGroup>
    <PostBuildEvent> YOUR COMMAND (With Macros or not) </PostBuildEvent>
</PropertyGroup>

So, you can build a small application that inserts at every .csproj file those tags with the desired command.

Hope helps!

EDIT:

Another (hardly) possibility its to develop your own task inheriting from Task, codig the Execute() method as you wish an then, linking the .dll file at the .csproj

  <!-- 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>
  -->