views:

682

answers:

1

Hi Is there a way to customize the post build event macros, I would like to move the new assembly to a sub folder in the same directory named by the version of the assembly i.e.

copy $(TargetDir)$(TargetFileName) $(TargetDir)$(ASSEMBLYVERSION)\$(TargetFileName)

However there is no such 'macro'. Sort of building a executable to get version like so

call foo.bat $(TargetName)

Where we have foo.bat evaluate the version of the target by calling a managed app that prints the version of the assembly you pass in, say GetVersion.exe

for /f %%t in ('GetVersion.exe %1') do (
        set _version=%%t
    )
echo %_version%

Any Ideas?? Surely there is a way to customize the macros directly??

+1  A: 

Not sure if it can be done through the post-build script, but you can modify the project file to do the same thing.

Right click on the project and select "Unload Project".

Then right click it again and select "Edit Project".

Now in the project file, find the "AfterBuild" target. It's normally at the bottom of the file and commented out.

Uncomment it, or just paste the following:

<Target Name="AfterBuild">
  <GetAssemblyIdentity AssemblyFiles="path\to\bin\$(Configuration)\$(OutputName).dll">
    <Output TaskParameter="Assemblies" ItemName="AssemblyVersion"/>
  </GetAssemblyIdentity>

  <Copy 
    SourceFiles="path\to\bin\$(Configuration)\$(OutputName).dll" 
    DestinationFiles="path\to\bin\$(Configuration)\%(AssemblyVersion.Version)\$(OutputName).dll" />
</Target>

Finally right click on the project again and select "Reload Project".

You may need to fiddle with the variable names, and possibly create the folder before copying into it. Hopefully this will help though.

Idea taken from Automated installer version numbers for WiX

Cameron MacFarland
Thanks, it has been helpful for me!
couellet