我会用git describe http://git-scm.com/docs/git-describe为了获取代表当前提交的标签/SHA1 的 id,并将其集成到您的程序集文件中。
v1.0-2-g2414721-DEV
^ ^ ^ ^
| | | \-- if a dirtyMarker was given, it will appear here if the repository is in "dirty" state
| | \---------- the "g" prefixed commit id. The prefix is compatible with what git-describe would return - weird, but true.
| \------------- the number of commits away from the found tag. So "2414721" is 2 commits ahead of "v1.0", in this example.
\----------------- the "nearest" tag, to the mentioned commit.
它类似于“使用 Android Studio/Gradle 从 git 描述自动对 Android 项目进行版本控制 https://stackoverflow.com/a/18021756/6309”,但要适应vb.net。
或者你可以有“假版本号 https://stackoverflow.com/a/10875137/6309".
有关更完整的构建程序集文件生成,请参阅那个 Maven 插件“maven-git-commit-id-plugin" https://github.com/ktoso/maven-git-commit-id-plugin(再次,适应 vb.net 版本)。
它可以生成一个完整的文件,如下所示:
{
"branch" : "testing-maven-git-plugin",
"describe" : "v2.1.0-2-g2346463",
"commitTime" : "06.01.1970 @ 16:16:26 CET",
"commitId" : "787e39f61f99110e74deed68ab9093088d64b969",
"commitIdAbbrev" : "787e39f",
"commitUserName" : "Konrad Malawski",
"commitUserEmail" : "[email protected] /cdn-cgi/l/email-protection",
"commitMessageFull" : "releasing my fun plugin :-)
+ fixed some typos
+ cleaned up directory structure
+ added license etc",
"commitMessageShort" : "releasing my fun plugin :-)",
"buildTime" : "06.01.1970 @ 16:17:53 CET",
"buildUserName" : "Konrad Malawski",
"buildUserEmail" : "[email protected] /cdn-cgi/l/email-protection"
}
这说明了如何向 git 存储库询问各种不同的信息(不仅仅是日期,还有分支、提交者、提交消息……)。
请参阅DescribeCommand.java https://github.com/ktoso/maven-git-commit-id-plugin/blob/master/src/main/java/pl/project13/jgit/DescribeCommand.java有关实施的更多详细信息。