2

I'm trying to get the output of git describe into my build as a preprocessor define, to use in versioning modules. Unfortunately, it's being a bit contrary (not sure where the issue is).

I had a pre-build event like:

 for /f "delims=" %a in ('git describe') do set GITID=%a

which works from the command prompt, but returned code 255 in the build (which caused an error). So I changed it to:

git describe > buildprops_gitid.txt
set /p GITID= < buildprops_gitid.txt

which again, works in command prompt (and doesn't error during build). The file is created with the correct value.

In the preprocessor settings, I then have:

BUILD_TARGETFILE=$(TargetFileName)
BUILD_GITID=$(GITID)

The former works fine, putting the target filename into the file as expected. The latter doesn't work, instead putting an empty string. I suspect this is related to the env var being lost somewhere along the way.

Is there a way to get the output of CLI programs and use that as variables ($(var)) within Visual Studio?

ssube
  • 47,010
  • 7
  • 103
  • 140

1 Answers1

0

the workaround i found for this was to generate an include file in a pre-build event. something like the following version.bat script:

@echo off
FOR /F "tokens=*" %%i IN ('call git describe --always') DO echo #define VCSVERSION "%%i" > vcsversion.h

and then add #include "vcsversion.h" in the code.

this is basically the solution i suggested here

Community
  • 1
  • 1
umläute
  • 28,885
  • 9
  • 68
  • 122