Search code examples
c#visual-studioassembliespost-processing

What is the proper build event to run assembly postprocessing in Visual Studio/MSBuild


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?


Solution

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