4

好的,我知道这可能不是传统的,但除此之外:我使用 AssemblyFileVersion 作为我的“构建名称”字符串。它的格式如下:

' File Version information for an assembly consists of the following four values:
'
'      Year
'      Month 
'      Day
'      Commit Number for that day
'
' Build Name can either be alpha | beta | hotfix | release
' alpha - is a development buildname with rapid changing API
' beta - is a production build for our beta users
' hotfix - is a production version with a bug fix
' release - is a standard issue production version.

<Assembly: AssemblyVersion("0.8.3")> 
<Assembly: AssemblyFileVersion("13.10.24.3")> 
<Assembly: AssemblyBuildName("alpha")>

不幸的是,我每次执行git提交时都必须调整 AssemblyInfo.vb 。现在我知道 GIT 实际上将提交存储在 .git 目录中多个位置的日志文件中。我的问题是:无论如何要自动化这个文件以从 git 文件中读取以查看年/月/日/commit#ForThatDay 并自动调整 AssemblyFileVersion (甚至是自定义 Assembly 属性)?

4

1 回答 1

4

我将使用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.

它类似于“ Automatically versioning Android project from git describe with Android Studio/Gradle ”,但要适应 vb.net。
或者你可以有“假修订号”。

要获得更完整的构建程序集文件生成,请参阅maven 插件“ 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" : "konrad.malawski@java.pl",
     "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" : "konrad.malawski@java.pl"
 }

这说明了如何向 git repo 询问各种不同的信息(不仅仅是日期,还有分支、提交者、提交消息……)。
有关实施DescribeCommand.java的更多详细信息,请参阅。

于 2013-11-01T22:31:42.610 回答