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?