msbuild: set a specific preprocessor #define in the command line

后端 未结 11 1655
借酒劲吻你
借酒劲吻你 2021-02-01 05:08

In a C++ file, I have a code like this:

#if ACTIVATE
#   pragma message( \"Activated\" )
#else
#   pragma message( \"Not Activated\")
#endif

I

11条回答
  •  攒了一身酷
    2021-02-01 05:45

    Maybe it is a bad idea to answer such old question, but recently I googled a similar problem and found this topic. I wrote a cmd script for some build system and I was succeed to find a solution. I leave it here for future generations (:

    According to @acemtp's problem, my solution would look like this:

    @echo off
    
    :: it is considered that Visual Studio tools are in the PATH
    if "%1"=="USE_ACTIVATE_MACRO" (
        :: if parameter USE_ACTIVATE_MACRO is passed to script
        :: the macro ACTIVATE will be defined for the project
        set CL=/DACTIVATE#1
    )
    call msbuild /t:Rebuild /p:Configuration=Release
    

    UPD: I tried to use set CL=/DACTIVATE=1 and it also worked, but the official documentation recommends to use number sign

提交回复
热议问题