Consider a situation in which Git is installed in Windows and is available only in Git Bash, not Windows cmd environment. Having a vdproj to create installer for an application, but need to intercalate the latest git hash to the MSI package's name. For example, at the moment it produces: Behnama.msi But we need it to produce: Behnama_49ee23d3b33ba0fa5ce0ac128f50ed00345e9ce3.msi The hash 49ee... is what in top when I enter 'git log' in Git Bash. When a new commit is created, then come and build the vdproj, I want the hash to be changed in the name of the msi file.
Latest git hash needs to be speicified in installer's name
188 Views Asked by hamidi At
3
There are 3 best solutions below
4

VDPROJ isn't MSBuild based so it can't do that much. Your best bet would be to have a postbuild command that renamed Product.msi to Product_%SHA%.msi.
6

You need a few steps
- Get the last git commit ID
- Write the ID to a wxi-file
- Include the wxi-file to original wxs-file
- Use the value as variable
For 1) you can use git log -1 --pretty=format:"%h"
(short hash) or git log -1 --pretty=format:"%H" (long hash)
to get the last commit id.
For 2) On a Windows System type git log -1 --pretty=format:"%H" > gitLastCommit.wxi
to store the last commit as a wxi-file. HINT: You need to wrap the simple ID with<include><?define mylastGitCommit = "VALUE OF COMMT ID" ?></include>
For 3) Add a similar line <?include .\gitLastCommit.wxi ?>
to your wxs file.
For 4) Use the defined variable $(var.mylastGitCommit)
in your wxs file where it is needed
A solution is to install ActivePerl or any perl binary to be able to run perl scripts. Then run it as a post build event. This perl script may obtain the hash I want:
The last statement might be something like this:
instead.