使用GIT自动执行AssemblyFileVersion增量 [英] Automate AssemblyFileVersion Incrementation using GIT

查看:152
本文介绍了使用GIT自动执行AssemblyFileVersion增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我知道这可能不是常规的,但除此之外:我将AssemblyFileVersion用作构建名称字符串的一种。格式如下:

Ok I understand that this is probably not conventional, but that aside: I am using the AssemblyFileVersion as kind of my "Build Name" string. It is formated like this:

' 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")>

不幸的是,我不得不调整AssemblyInfo.vb 每次 git提交。现在我知道GIT实际上将提交存储在.git目录中多个位置的日志文件中。我的问题是:是否有自动化此文件以从git文件读取以查看年/月/日/ commit#ForThatDay并自动调整AssemblyFileVersion(甚至是自定义的Assembly Attribute)的方法?

Unfourtunately I am having to adjust the AssemblyInfo.vb EVERY TIME I do a git commit. Now I know GIT actually stores the commits in like a log file several places in the .git directory. My question is: is there anyway to automate this file to read from the git files to see what the year/month/day/commit#ForThatDay and automatically adjust the AssemblyFileVersion (or even a custom Assembly Attribute)?

推荐答案

我会使用 git describe 以获得代表当前提交的标记/ SHA1的ID,并将其集成到您的Assembly文件中。

I would use git describe in order to get an id representing the tag/SHA1 of the current commit, and integrate it in your Assembly file.

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.

类似于 从git自动对Android项目进行版本控制,可使用Android Studio / Gradle 进行描述,但要适应vb.net。

或者,您也可以使用 伪造的修订版号

It is similar to "Automatically versioning Android project from git describe with Android Studio/Gradle", but to be adapted to vb.net.
Or you can have "fake revision number".

有关生成更完整的装配文件的信息,请参见那个maven插件 maven-git-commit-id-插件 (同样适用于vb.net构建)。

它可以生成完整的文件,如下所示:

For a more complete build Assembly file generation, see that maven plugin "maven-git-commit-id-plugin" (again, to be adapted to a vb.net build).
It can generate a file as complete as:

{
     "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 了解有关实现的更多详细信息。

That illustrates how you can ask the git repo for all kind of different information (not just the date, but the branch, committer, commit message, ...).
See the DescribeCommand.java for more details on the implementation.

这篇关于使用GIT自动执行AssemblyFileVersion增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆