Search code examples
c++visual-studio-2010batch-fileenvironment-variablespre-build-event

how to add environment variables in VS2010 using .bat file?


I have a batch file with this code:

@echo off
set VAR=7
echo the version is %VAR%

I want to add this .bat file to my visual studio project, using pre-build event. I wrote in the pre build event the path to the batch file, but then when I enter the : Resources ->PreProcessor definitions - I can't see the VAR How can I add it? any help would be appreciated!!


Solution

  • Change your BAT script to be something like

    echo #define VER 7 > version.h
    

    and then have your code use

    #include "version.h"