0

考虑一下 Git 安装在 Windows 中并且仅在 Git Bash 中可用,而不是在 Windows cmd 环境中可用的情况。拥有一个 vdproj 来为应用程序创建安装程序,但需要将最新的 git 哈希插入到 MSI 包的名称中。例如,目前它产生:Behnama.msi 但我们需要它来产生:Behnama_49ee23d3b33ba0fa5ce0ac128f50ed00345e9ce3.msi 当我在 Git Bash 中输入“git log”时,哈希 49ee... 是顶部的内容。当创建一个新的提交时,然后来构建 vdproj,我希望以 msi 文件的名称更改哈希。

4

3 回答 3

0

一个解决方案是安装 ActivePerl 或任何 perl 二进制文件以便能够运行 perl 脚本。然后将其作为构建后事件运行。这个 perl 脚本可以获得我想要的哈希值:

$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";

最后一条语句可能是这样的:

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

反而。

于 2020-02-04T18:53:29.940 回答
0

VDPROJ 不是基于 MSBuild,所以它不能做那么多。最好的办法是使用一个将 Product.msi 重命名为 Product_%SHA%.msi 的构建后命令。

于 2020-02-04T13:25:40.677 回答
0

你需要几个步骤

  1. 获取最后一个 git 提交 ID
  2. 将 ID 写入 wxi 文件
  3. 将 wxi 文件包含到原始 wxs 文件中
  4. 使用值作为变量

对于 1) 您可以使用git log -1 --pretty=format:"%h"(short hash) 或git log -1 --pretty=format:"%H" (long hash)获取最后一个提交 ID。

对于 2) 在 Windows 系统类型git log -1 --pretty=format:"%H" > gitLastCommit.wxi上将最后一次提交存储为 wxi 文件。提示:您需要将简单 ID 包装为<include><?define mylastGitCommit = "VALUE OF COMMT ID" ?></include>

<?include .\gitLastCommit.wxi ?>对于 3)在您的 wxs 文件中添加类似的行。

对于 4)$(var.mylastGitCommit)在需要的地方使用 wxs 文件中定义的变量

于 2020-02-20T14:08:07.907 回答