Hook git command into visual studio pre build step
So basically I want to turn the output of the command
- Access denied writing to VS project .suo when trying to merge branches with TFS & GIT
- How to move a project from Git to TFS in Visual Studio
- Best practice for creating subversion repositories?
- Visual Studio (Git provider) permanently shows “pending edit” on all files
- Replicate Gated check-in functionality in Visual Studio + VSO + Git
- Visual Studio Online - The version descriptor <BranchName> could not be resolved
git rev-parse HEAD
into a define that I can embed in the output binary.
Thanks in advance.
2 Solutions collect form web for “Hook git command into visual studio pre build step”
post-commit githook, you can put it into a file. I think git on windows comes with a bourne shell, so the following would work in a post-commit hook.
#!/bin/sh GIT_SHA_INCLUDE_FILE=foo.h echo -n '#define GIT_SHA ' > $GIT_SHA_INCLUDE_FILE git rev-parse HEAD >> $GIT_SHA_INCLUDE_FILE
And save that as .git/hooks/post-commit
The file should remain untracked since it’s (nearly) impossible to include the hash of the commit within the commit itself.
Frankly, I prefer a pre-build events in Visual Studio over Git post-commit. There is additional benefit of knowing if you building from a dirty repository or not. Did the write-up on that today. Here are the general steps from build to execution:
The build process has a pre-build script, which gathers version and repository status information. In our case, VC++ uses the Windows PowerShell
The pre-build script generates a source code file, which is expected by the rest of the codebase. The generated file has everything needed to allow or deny running the version. In our case it is a C++ header file
A code contains function which checks if the build is legitimate to run, and logs and stops the process as needed. That example code is in the
versionLogAndVet function of the
version.cpp example file.
At run time, the
versionLogAndVet function allows to run only permitted combinations of repository status / build configuration. It also logs version information.
The specifics and code examples are at the full post.