6

I need to write git information: Commit name, tags, branch, etc to a binary (exe) file.

It is needed to run strings * | grep git, on that file to simply view latest git info about it. I know that AssemblyInfo is displayed when I run this command (without grep), but I'm facing two possible problems:

  1. I'm not sure if I can write to AssemblyInfo from code, to run 'git log' command and then get its output and write into AssemblyInfo.

  2. If I want to use command 'git log' then it's not going to work on Windows, but it is possible that my App will be built on Windows and not on unix environment.

Maybe you know another way to do that?

Rui Jarimba
  • 11,166
  • 11
  • 56
  • 86
alexander_va
  • 143
  • 7

2 Answers2

2

This is usually done in your build script, filling a templated version of your AssemblyInfo (look at mustache, a templating language).

This build step does the following:

Then your software build continues as usual.

Community
  • 1
  • 1
CharlesB
  • 86,532
  • 28
  • 194
  • 218
  • Well, I didn't actually understood what you mean 'look at mustache'. But I'm facing problem when I try to build my app on windows machine, because I can't run 'git' commands since they're not built in cmd. – alexander_va Mar 06 '13 at 14:09
  • 1
    @user1243496: Just add the path to git.exe to your `PATH` environment variable. – Daniel Hilgarth Mar 06 '13 at 14:10
  • that sounds nice, but I need more universal way, for example If I want to build it on machine where no git.exe in PATH environment variable. Another way is to read files in .git folder, but I find it impractical.. – alexander_va Mar 06 '13 at 14:14
  • 2
    IMHO you're adding too much constraints by wanting to build on a machine without git in PATH. It is possible, but why? this info is very difficult to get without git, and git is installable in a matter of minutes. If you insist you can include a portable git along with your code, but I find it akward. – CharlesB Mar 06 '13 at 14:23
  • Thanks for you opinion, I really appreciate it. Well, I'll re-consider that part. Will try in few moments your answer, It seems to be the perfect solution. – alexander_va Mar 06 '13 at 14:25
0

There is a .net wrapper for Git windows implementation. Some high profile projects use this implementation. https://github.com/libgit2/libgit2sharp, http://libgit2.github.com/

Syam
  • 1,629
  • 1
  • 20
  • 32