0

I'm using PostSharp alternative called AfterThought to postprocess some of projects in my solution. Unfortunately it looks like project's post-build event command line property isn't the right extension point where to plug the post-processor in, because the compiled assembly is copied to some of the dependent projects before post-build event is fired and postprocessor run. It's interesting that the problem occurss only for web site and web service projects - dependent class libraries got post-processed version of the assembly, but I guess the core of the problem is in the post-build event is invoked too late and that I should use different event.

So I guess I need to enhance the build process/MSBuild of my projects directly in *.csproj files - is that right? And what build event is the right one for invocation of command line assembly post-processor?

Gunther Piez
  • 29,760
  • 6
  • 71
  • 103
Buthrakaur
  • 1,821
  • 3
  • 23
  • 35
  • 1
    Haven't had a chance to use either one, but off-hand I would guess that you'd be able to install PostSharp and look at its targets file to figure out how/when/where it adds itself to the build process, then just do the same for AfterThought? This blog post makes it appear that they add themselves in CompileDependsOn? http://www.sharpcrafters.com/blog/post/under-the-hood-of-msbuild-integration.aspx – James Manning May 06 '12 at 20:49
  • I just tried to use CompileDependsOn, but it looks like the assembly ($(TargetPath)) isn't available in the project output yet. $(CompileDependsOn); AfterThought; – Buthrakaur May 07 '12 at 06:06
  • I just discovered I have to use @(IntermediateAssembly) instead of $(TargetPath) in CompileDependsOn. After I applied this tweak the build process started to work as I intended. – Buthrakaur May 07 '12 at 08:45

2 Answers2

0

There are two:

  • <Target Name="AfterBuild" will run MSBuild commands
  • <PropertyGroup><PostBuildEvent> will run shell commands, and is accessable from Visual Studio's project dialog as "Post-build event command line" under the "Build Events" tab
robrich
  • 13,017
  • 7
  • 36
  • 63
  • PostBuildEvent is the one I tried so far, but it's being executed too late - the assemblies are already copied to dependent projects (before the post-processor is run). I just tried AfterBuild target, but the result is same. I need some build event which occurs just before compiled assembly is copied to dependent projects. – Buthrakaur May 06 '12 at 15:47
  • Unless I'm mistaken, it does the current project build to completion -- including both these events -- before copying assemblies to referenced projects. How is the copy done? Is it just project references? Perhaps did you link to the assembly inside /bin/Debug instead? Is the project build order such that this other project is actually building first? – robrich May 06 '12 at 15:53
  • It's project references and the build order is right. The thing is it works when dependent project is simple class library - problem occurs just with web site and web application projects. I just tried to use AfterCompile event, but it looks like the assembly doesn't exist yet in the output folder.. – Buthrakaur May 06 '12 at 16:00
  • Can you do it as a of the web app project? – robrich May 06 '12 at 16:03
  • Yes, I could, but it would be very ugly and non-systematic. The solution is quite big (over 30 projects) and lot of the projects are being post-processed. I could also create empty project integrated into project dependency/build chain, which would just invoke the post-processor, but I'm loking for clean solution - that means invoking the post-processor from project itself.. – Buthrakaur May 06 '12 at 16:19
0

The final solution to my problem is CompileDependsOn target:

  <Target Name="AfterThought">
    <Exec Command="&quot;$(SolutionDir)..\LIBS\Afterthought\Afterthought.Amender.exe&quot; &quot;@(IntermediateAssembly->'%(FullPath)')&quot; &quot;$(SolutionDir)..\Amendments\bin\$(Configuration)\Amendments.dll&quot; @(ReferencePath->'&quot;%(RootDir)%(Directory).&quot;', ' ')" />
  </Target>
  <PropertyGroup>
    <CompileDependsOn>
    $(CompileDependsOn);
    AfterThought;
   </CompileDependsOn>
  </PropertyGroup>
Buthrakaur
  • 1,821
  • 3
  • 23
  • 35