0

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.

hamidi
  • 1,343
  • 1
  • 12
  • 22
  • 1
    Personally I think this is a horrible user experience. I don't know of a single application in the world that names their MSIs this way. Users don't know or care what the SHA of the source used to create an MSI. They care about the version number at most. If this is for traceability you can store it in the summary information stream of the MSI using the WiX Product@Description element. – Christopher Painter Feb 22 '20 at 23:17
  • What is WiX Product? – hamidi Feb 23 '20 at 10:25
  • Sorry I meant the Wix Package element / Description attribute. https://wixtoolset.org/documentation/manual/v3/xsd/wix/package.html – Christopher Painter Feb 23 '20 at 13:55
  • Sorry I couldn't find how to use it. Is it an extension to VS that provides more properties for a vdproj file and causes the resulting MSI show more metadata in its properties when opened via explorer? – hamidi Feb 23 '20 at 15:39
  • I'm sorry, I crossed my wires and thought I was answering a WiX question. For VDPROJ you'd have to write a postbuild script to programatically update the MSI after it's built. – Christopher Painter Feb 23 '20 at 23:07
  • Oh I see. Yeah I wrote a C# application to extract the last commit id directly from .git folder files and rename the MSI file. I don't know whether it's possible to add metadata to the file after it's built. – hamidi Feb 24 '20 at 08:34
  • Take a look at a DLL found in WiX toolset caled Microsoft.Deployment.WindowsInstaller. You can easily use it to open the MSI as a database, update the summaryinformation stream and save the MSI. You'll want to resign it after. – Christopher Painter Feb 24 '20 at 13:58
  • Ok thx. I'll see whether it's ok for the company to use metadata for the info instead of the MSI file name and if it's ok I'll use the DLL. – hamidi Feb 25 '20 at 13:02

3 Answers3

0

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.

Christopher Painter
  • 52,390
  • 6
  • 60
  • 97
0

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:

$folder = '';
while (! -d "$folder.git") {
    $folder .= '../';
}
open IF, "$folder.git/logs/HEAD" or die $!;
while (<IF>) {
    s/\s+$//;
    $lastline = $_ if $_;
}
close IF;
@ar = split /\s+/, $lastline;
print "$ar[1]\n";

The last statement might be something like this:

rename("Behnama.msi", "Behnama_$ar[1].msi");

instead.

hamidi
  • 1,343
  • 1
  • 12
  • 22
0

You need a few steps

  1. Get the last git commit ID
  2. Write the ID to a wxi-file
  3. Include the wxi-file to original wxs-file
  4. 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

KargWare
  • 810
  • 1
  • 9
  • 25
  • The problem is the environment I'm going to run git. Please concentrate on the question. git is only available in git bash. so I can't run git log ... from inside the VS. – hamidi Feb 22 '20 at 10:26
  • Git can be installed in windows, I think even without git bash. Which VS Version are you using? – KargWare Feb 22 '20 at 18:21
  • 2010. Windows installations are forced by the company to install Git out of normal cmd, Windows command line, and to be installed only in Git Bash environment. – hamidi Feb 23 '20 at 10:27
  • Modern Visual Studios have the "Developer Command Prompt", it is a normal Windows Terminal with some special PATH variables, I my case VS 2017 and VS 2019 git in in that path registered. So I would suggest to you just "try" `git log` on one of your terminals. – KargWare Feb 23 '20 at 15:43
  • It says that git is not available. I'm using VS 2010 – hamidi Feb 23 '20 at 16:19
  • Can you check the folder `C:\Program Files\Git\bin` maybe git is installed but not part of `PATH`. How do you do your commits / push / pull tasks to your git server? – KargWare Feb 24 '20 at 06:13