none
Issues with Preprocessor Macro being defined to Environment Variable in Visual Studio RRS feed

  • Question

  • Hello,

    I am trying to create a program where I will set an environment variable in the batch file that launches the solution in order for #if (macro) defines to compile certain portions of code.  My issue is that the Visual Studio IDE does not seem to pick up on what the macro definition is when I reload the application.

    For example, if I define my environment variable to be "0" and compile the chunk inside of the #if/#endif block won't compile.  The IDE will still display it as a non-zero number and give the appearance that the preprocessor block is active.   I realize I have to recompile anytime I load the IDE with a different environment variable, my issue just comes in with the IDE itself seemingly not picking up on any change I make to the variable.  I can modify the batch file, change the number, save it, then restart VS and it will never register. 

    I'm confused on why that is and if there's anything I have to do to make sure the IDE can picture it properly.  If there's nothing that can be done and I just have to be cognizant of the environment variable before I run the batch file for the application that's fine too.  Thanks for any help.

    Tuesday, August 13, 2019 11:48 PM

All replies

  • Hi RudeOfTheTurks,

    Welcome to the MSDN forum.

    According to your description, l have just create a bat file to start and compile the solution and l also have some variables in this file. You can refer this as below:

    If this does not help you, please share the batch file and other key screenshots and tell us about how you set the environment variable.

    BTW, you can also redirect this issue to the Stack Overflow with tag batch-file and visual studio for better help.

    Best Regards,

    Perry


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Wednesday, August 14, 2019 6:05 AM
  • Does it help if you right-click inside any source file, then select “Rescan Solution” and wait a little?


    • Edited by Viorel_MVP Wednesday, August 14, 2019 6:30 AM
    Wednesday, August 14, 2019 6:29 AM
  • Hi RudeOfTheTurks,

    Did your issue solved?If your issue still persists, please run the batch file as Administrator.

    Also, do not forget to set vs to administrator startup mode.

    •  find the devenv.exe in the system file and right-click it and select "Troubleshoot compatibility"
    • check "The program requires additional permissions"--> click "Next"-->click "Test the program"
    • click "next"
    • select "Yes ,save these settings for this program"

    More information you can refer to this:

    https://stackoverflow.com/questions/9654833/how-do-i-run-visual-studio-as-an-administrator-by-default/41758824#41758824

    Best Regards,

    Perry


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, August 19, 2019 9:46 AM