简体   繁体   中英

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?

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM