2013-10-24 76 views
4

好吧,我明白,這可能不是傳統的,但那一邊:我使用AssemblyFileVersion作爲我的「生成名稱」字符串的一種。這是格式化這樣的:使用GIT自動化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")> 

Unfourtunately我不必調整AssemblyInfo.vb中EVERY TIME我做了git的承諾。現在我知道GIT實際上將提交存儲在.git目錄中幾個地方的日誌文件中。我的問題是:是否有自動此文件從git文件中讀取以查看年/月/日/提交#ForThatDay並自動調整AssemblyFileVersion(甚至自定義Assembly Attribute)?

+0

你可能想要預先提交某種鉤子。不重複,但相關:http://stackoverflow.com/q/12890755/945456 –

回答

4

我會使用git describe爲了得到一個代表當前提交的標記/ SHA1的id,並將它集成到你的Assembly文件中。

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。
或者你可以有「fake revision number」。

有關更完整的生成彙編文件生成,請參見that maven plugin "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]", 
    "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]" 
} 

這說明了如何可以問混帳回購協議於各種不同的信息(不只是日期,但分支,提交者,提交信息,.. )。
有關實施的更多詳情,請參閱DescribeCommand.java