locked
Msbuild not reading preprocess value when running ? RRS feed

  • Question

  • User1253338400 posted

    I have a .net solution in visual studio. I have preporcessor definitiions as follows:

        #if !LIVE
            private const string teststr = "live";
        #elif (TEST || DEBUG)
            private const string teststr = "test"
        #else
            private const string teststr =  = 'other"
        #endif


    I compile the solution as follows

         MSBuild.exe C:\Projects\Testing.sln /property:Configuration=Release

    to set the preporcessor value do i bneed to do the following

         MSBuild.exe C:\Projects\Testing.sln /property:Configuration=Release /d:TEST

    Will this take the value of teststr as test ?

    Friday, March 19, 2021 4:27 AM

Answers

  • User-1330468790 posted

    Hi robby32,

     

    Will this take the value of teststr as test ?

    No, it will not take the value as test since you don't define the constants at all.

    By default, when you set "Configuration=debug", it actually defines two constants "DEBUG" and "TRACE". 

    You could refer to this link: 
    https://docs.microsoft.com/en-us/visualstudio/ide/understanding-build-configurations?view=vs-2019#project-configurations

    That way, you are able to get the value of 'teststr' as "test" where the "DEBUG" works.

     

    If you set "Configuration=Release", what you could get is "other" since "LIVE","DEBUG" and "TEST" can not be found.

    Instead, you could try below way to self-define the constants in command.

    To get "live":

    MSBuild.exe C:\Projects\Testing.sln /property:Configuration=Release /t:Rebuild /p:DefineConstants="LIVE"

    To get "test"

    MSBuild.exe C:\Projects\Testing.sln /property:Configuration=Release /t:Rebuild /p:DefineConstants="TEST"
    OR
    MSBuild.exe C:\Projects\Testing.sln /property:Configuration=Release /t:Rebuild /p:DefineConstants="DEBUG"

    To get "other"

    MSBuild.exe C:\Projects\Testing.sln /property:Configuration=Release /t:Rebuild /p:DefineConstants=""

     

    You could read below documentations for more details.

    sets the global Configuration property to DEBUG.

    MSBuild command-line reference

     

    Hope helps.

    Best regards,

    Sean

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 23, 2021 2:16 PM