4
votes

I have a long afterbuild process on my Visual Studio project file's after build target, as show below.

The issue is that it always runs the AfterBuild target when I hit build even when the actual source code has not changed and the project is not compiled.

How can I have this only run when the project has been compiled and the physical binary is written or update on the disk?

<Target Name="AfterBuild">

 <Exec Command="&quot;$(ProgramFiles)\Microsoft\ILMerge\ILMerge.exe&quot; /copyattrs /log /target:library /targetplatform:4,C:\Windows\Microsoft.NET\Framework64\v4.0.30319 /Lib:&quot;$(TargetDir)\&quot; /keyfile:&quot;$(ProjectDir)\Plugin.snk&quot; /out:&quot;$(TargetDir)\$(AssemblyName).merged.dll&quot; &quot;$(AssemblyName).dll&quot; &quot;PluginCommandCommon.dll&quot; &quot;Common.dll&quot;" />

 <Copy SourceFiles="$(TargetDir)\$(AssemblyName).merged.dll" DestinationFolder="$(ProjectDir)..\PluginPackage\bin\$(Configuration)\" />

</Target>
2
Yes, this looks like the answers is the link, will investigate moreSimon
Can't really make sense of the answer in the link, I think I'm missing something. Effectively all I want to do is run some ms build tasks when ever the project has been build and files have been written to the bin dir.Simon

2 Answers

5
votes

Option 1: Instead of AfterBuild use AfterRebuild (one of MSBuild's many undocumented features):

<Target Name="AfterRebuild" >...</Target>

Option 2:

Hook up one of the incremental build's conditions:

<Target Name="AfterBuild" Condition=" '@(_SourceItemsToCopyToOutputDirectory)' != '' " >

UPDATE:

Using MSBuild Extension Pack's ILMerge task will allow better control, I.E check for each file existence:

<Target Name="ILMergeItems">
    <ItemGroup>
        <Input Include="C:\b\MSBuild.ExtensionPack.dll"/>
        <Input Include="C:\b\Ionic.Zip.dll"/>
    </ItemGroup>
    <MSBuild.ExtensionPack.Framework.ILMerge
        Condition="Exists('%(Input.FullPath)')"
        InputAssemblies="@(Input)"
        OutputFile="C:\a\MyNewAssembly.dll"/>
</Target>
-2
votes

There is a ComboBox in Properties>>Build Events>>Run the post-build event...if this is what you mean.