سؤال

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

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)?

هل كانت مفيدة؟

المحلول

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.

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".

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"
 }

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top