Programmatically check the build configuration











up vote
6
down vote

favorite












Using the DEBUG configuration, I can switch behaviour on and off using this type of syntax:



#if DEBUG
Console.WriteLine("Debug");
#else
Console.WriteLine("Not Debug");
#endif


However, if I set up a different configuration, say: TEST then this doesn't work:



#if TEST
Console.WriteLine("Test");
#else
Console.WriteLine("Not Test");
#endif


Is there a way to check these?










share|improve this question
























  • read this stackoverflow.com/questions/3167617/…
    – NinjaDeveloper
    Jul 15 '16 at 12:42










  • Add "TEST" to Project Properties -> Build -> Conditional Compilation Symbols, and it works
    – user6522773
    Jul 15 '16 at 12:43






  • 1




    For the record - you don't actually check the configuration in your program. #if is a pre-compiler directive, that means it is being executed in the process of the compilation. So the #if .. #else structure isn't a part of your program.
    – enkryptor
    Jul 16 '16 at 17:35










  • Note, you may need to restart Visual Studio for this to display properly in the editor. I did on VS 2017. However, the compilation works as you would expect even without a restart. Seems to be an issue with the rendering of directives.
    – David
    Oct 10 at 19:05

















up vote
6
down vote

favorite












Using the DEBUG configuration, I can switch behaviour on and off using this type of syntax:



#if DEBUG
Console.WriteLine("Debug");
#else
Console.WriteLine("Not Debug");
#endif


However, if I set up a different configuration, say: TEST then this doesn't work:



#if TEST
Console.WriteLine("Test");
#else
Console.WriteLine("Not Test");
#endif


Is there a way to check these?










share|improve this question
























  • read this stackoverflow.com/questions/3167617/…
    – NinjaDeveloper
    Jul 15 '16 at 12:42










  • Add "TEST" to Project Properties -> Build -> Conditional Compilation Symbols, and it works
    – user6522773
    Jul 15 '16 at 12:43






  • 1




    For the record - you don't actually check the configuration in your program. #if is a pre-compiler directive, that means it is being executed in the process of the compilation. So the #if .. #else structure isn't a part of your program.
    – enkryptor
    Jul 16 '16 at 17:35










  • Note, you may need to restart Visual Studio for this to display properly in the editor. I did on VS 2017. However, the compilation works as you would expect even without a restart. Seems to be an issue with the rendering of directives.
    – David
    Oct 10 at 19:05















up vote
6
down vote

favorite









up vote
6
down vote

favorite











Using the DEBUG configuration, I can switch behaviour on and off using this type of syntax:



#if DEBUG
Console.WriteLine("Debug");
#else
Console.WriteLine("Not Debug");
#endif


However, if I set up a different configuration, say: TEST then this doesn't work:



#if TEST
Console.WriteLine("Test");
#else
Console.WriteLine("Not Test");
#endif


Is there a way to check these?










share|improve this question















Using the DEBUG configuration, I can switch behaviour on and off using this type of syntax:



#if DEBUG
Console.WriteLine("Debug");
#else
Console.WriteLine("Not Debug");
#endif


However, if I set up a different configuration, say: TEST then this doesn't work:



#if TEST
Console.WriteLine("Test");
#else
Console.WriteLine("Not Test");
#endif


Is there a way to check these?







c# .net c-preprocessor preprocessor-directive






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 16 '16 at 17:31









Brian Tompsett - 汤莱恩

4,1631336100




4,1631336100










asked Jul 15 '16 at 12:40









pm_2

6,51930117213




6,51930117213












  • read this stackoverflow.com/questions/3167617/…
    – NinjaDeveloper
    Jul 15 '16 at 12:42










  • Add "TEST" to Project Properties -> Build -> Conditional Compilation Symbols, and it works
    – user6522773
    Jul 15 '16 at 12:43






  • 1




    For the record - you don't actually check the configuration in your program. #if is a pre-compiler directive, that means it is being executed in the process of the compilation. So the #if .. #else structure isn't a part of your program.
    – enkryptor
    Jul 16 '16 at 17:35










  • Note, you may need to restart Visual Studio for this to display properly in the editor. I did on VS 2017. However, the compilation works as you would expect even without a restart. Seems to be an issue with the rendering of directives.
    – David
    Oct 10 at 19:05




















  • read this stackoverflow.com/questions/3167617/…
    – NinjaDeveloper
    Jul 15 '16 at 12:42










  • Add "TEST" to Project Properties -> Build -> Conditional Compilation Symbols, and it works
    – user6522773
    Jul 15 '16 at 12:43






  • 1




    For the record - you don't actually check the configuration in your program. #if is a pre-compiler directive, that means it is being executed in the process of the compilation. So the #if .. #else structure isn't a part of your program.
    – enkryptor
    Jul 16 '16 at 17:35










  • Note, you may need to restart Visual Studio for this to display properly in the editor. I did on VS 2017. However, the compilation works as you would expect even without a restart. Seems to be an issue with the rendering of directives.
    – David
    Oct 10 at 19:05


















read this stackoverflow.com/questions/3167617/…
– NinjaDeveloper
Jul 15 '16 at 12:42




read this stackoverflow.com/questions/3167617/…
– NinjaDeveloper
Jul 15 '16 at 12:42












Add "TEST" to Project Properties -> Build -> Conditional Compilation Symbols, and it works
– user6522773
Jul 15 '16 at 12:43




Add "TEST" to Project Properties -> Build -> Conditional Compilation Symbols, and it works
– user6522773
Jul 15 '16 at 12:43




1




1




For the record - you don't actually check the configuration in your program. #if is a pre-compiler directive, that means it is being executed in the process of the compilation. So the #if .. #else structure isn't a part of your program.
– enkryptor
Jul 16 '16 at 17:35




For the record - you don't actually check the configuration in your program. #if is a pre-compiler directive, that means it is being executed in the process of the compilation. So the #if .. #else structure isn't a part of your program.
– enkryptor
Jul 16 '16 at 17:35












Note, you may need to restart Visual Studio for this to display properly in the editor. I did on VS 2017. However, the compilation works as you would expect even without a restart. Seems to be an issue with the rendering of directives.
– David
Oct 10 at 19:05






Note, you may need to restart Visual Studio for this to display properly in the editor. I did on VS 2017. However, the compilation works as you would expect even without a restart. Seems to be an issue with the rendering of directives.
– David
Oct 10 at 19:05














2 Answers
2






active

oldest

votes

















up vote
5
down vote



accepted










The DEBUG constant is a special one, and there's a setting for each project in each configuration whether it should be defined. The default is that it's on in Debug and off in Release, but it's completely configurable - open the properties page for a project and look under "Build", and there's a checkbox there saying "Define DEBUG constant."



Thus, defining a new build configuration, does not automatically give you any other compile constants for free. But that doesn't mean you can't create them manually.



To create a compile constant, add it to the list of "Conditional Compilation Symbols" - but make sure to do so in the correct build configuration.






share|improve this answer




























    up vote
    4
    down vote













    Yes you can use different configurations.
    DEBUG symbol is generated automatically if you choose Debug configuration in your configuration manager. You can check it. Go to Your project -> Properties -> Build -> Define DEBUG constant



    If you need to use additional constant just enter your own in Conditional compilation symbols.



    Steps for your case:




    1. Go to Your project -> Properties -> Build

    2. Switch configuration to Test

    3. Enter TEST to Conditional compilation symbols field


    Run your code and enjoy :)






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38396377%2fprogrammatically-check-the-build-configuration%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      5
      down vote



      accepted










      The DEBUG constant is a special one, and there's a setting for each project in each configuration whether it should be defined. The default is that it's on in Debug and off in Release, but it's completely configurable - open the properties page for a project and look under "Build", and there's a checkbox there saying "Define DEBUG constant."



      Thus, defining a new build configuration, does not automatically give you any other compile constants for free. But that doesn't mean you can't create them manually.



      To create a compile constant, add it to the list of "Conditional Compilation Symbols" - but make sure to do so in the correct build configuration.






      share|improve this answer

























        up vote
        5
        down vote



        accepted










        The DEBUG constant is a special one, and there's a setting for each project in each configuration whether it should be defined. The default is that it's on in Debug and off in Release, but it's completely configurable - open the properties page for a project and look under "Build", and there's a checkbox there saying "Define DEBUG constant."



        Thus, defining a new build configuration, does not automatically give you any other compile constants for free. But that doesn't mean you can't create them manually.



        To create a compile constant, add it to the list of "Conditional Compilation Symbols" - but make sure to do so in the correct build configuration.






        share|improve this answer























          up vote
          5
          down vote



          accepted







          up vote
          5
          down vote



          accepted






          The DEBUG constant is a special one, and there's a setting for each project in each configuration whether it should be defined. The default is that it's on in Debug and off in Release, but it's completely configurable - open the properties page for a project and look under "Build", and there's a checkbox there saying "Define DEBUG constant."



          Thus, defining a new build configuration, does not automatically give you any other compile constants for free. But that doesn't mean you can't create them manually.



          To create a compile constant, add it to the list of "Conditional Compilation Symbols" - but make sure to do so in the correct build configuration.






          share|improve this answer












          The DEBUG constant is a special one, and there's a setting for each project in each configuration whether it should be defined. The default is that it's on in Debug and off in Release, but it's completely configurable - open the properties page for a project and look under "Build", and there's a checkbox there saying "Define DEBUG constant."



          Thus, defining a new build configuration, does not automatically give you any other compile constants for free. But that doesn't mean you can't create them manually.



          To create a compile constant, add it to the list of "Conditional Compilation Symbols" - but make sure to do so in the correct build configuration.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jul 15 '16 at 12:45









          Tomas Aschan

          34.8k33163312




          34.8k33163312
























              up vote
              4
              down vote













              Yes you can use different configurations.
              DEBUG symbol is generated automatically if you choose Debug configuration in your configuration manager. You can check it. Go to Your project -> Properties -> Build -> Define DEBUG constant



              If you need to use additional constant just enter your own in Conditional compilation symbols.



              Steps for your case:




              1. Go to Your project -> Properties -> Build

              2. Switch configuration to Test

              3. Enter TEST to Conditional compilation symbols field


              Run your code and enjoy :)






              share|improve this answer

























                up vote
                4
                down vote













                Yes you can use different configurations.
                DEBUG symbol is generated automatically if you choose Debug configuration in your configuration manager. You can check it. Go to Your project -> Properties -> Build -> Define DEBUG constant



                If you need to use additional constant just enter your own in Conditional compilation symbols.



                Steps for your case:




                1. Go to Your project -> Properties -> Build

                2. Switch configuration to Test

                3. Enter TEST to Conditional compilation symbols field


                Run your code and enjoy :)






                share|improve this answer























                  up vote
                  4
                  down vote










                  up vote
                  4
                  down vote









                  Yes you can use different configurations.
                  DEBUG symbol is generated automatically if you choose Debug configuration in your configuration manager. You can check it. Go to Your project -> Properties -> Build -> Define DEBUG constant



                  If you need to use additional constant just enter your own in Conditional compilation symbols.



                  Steps for your case:




                  1. Go to Your project -> Properties -> Build

                  2. Switch configuration to Test

                  3. Enter TEST to Conditional compilation symbols field


                  Run your code and enjoy :)






                  share|improve this answer












                  Yes you can use different configurations.
                  DEBUG symbol is generated automatically if you choose Debug configuration in your configuration manager. You can check it. Go to Your project -> Properties -> Build -> Define DEBUG constant



                  If you need to use additional constant just enter your own in Conditional compilation symbols.



                  Steps for your case:




                  1. Go to Your project -> Properties -> Build

                  2. Switch configuration to Test

                  3. Enter TEST to Conditional compilation symbols field


                  Run your code and enjoy :)







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jul 15 '16 at 12:49









                  eldrex

                  537




                  537






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38396377%2fprogrammatically-check-the-build-configuration%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      Academy of Television Arts & Sciences

                      L'Équipe

                      1995 France bombings