使用 GIT 自动增加 AssemblyFileVersion [英] Automate AssemblyFileVersion Incrementation using GIT

查看:23
本文介绍了使用 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 commit.现在我知道 GIT 实际上将提交像日志文件一样存储在 .git 目录中的多个位置.我的问题是:有没有办法让这个文件自动从 git 文件中读取,看看年/月/日/commit#ForThatDay 是什么,并自动调整 AssemblyFileVersion(甚至自定义程序集属性)?

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,并将其集成到您的程序集文件中.

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.

它类似于使用 Android Studio/Gradle 从 git describe 自动版本控制 Android 项目",但需要进行调整到 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-plugin"(再次适应 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天全站免登陆