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?
c# .net c-preprocessor preprocessor-directive
add a comment |
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?
c# .net c-preprocessor preprocessor-directive
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
add a comment |
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?
c# .net c-preprocessor preprocessor-directive
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
c# .net c-preprocessor preprocessor-directive
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
add a comment |
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
add a comment |
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.
add a comment |
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:
- Go to Your project -> Properties -> Build
- Switch configuration to Test
- Enter TEST to Conditional compilation symbols field
Run your code and enjoy :)
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Jul 15 '16 at 12:45
Tomas Aschan
34.8k33163312
34.8k33163312
add a comment |
add a comment |
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:
- Go to Your project -> Properties -> Build
- Switch configuration to Test
- Enter TEST to Conditional compilation symbols field
Run your code and enjoy :)
add a comment |
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:
- Go to Your project -> Properties -> Build
- Switch configuration to Test
- Enter TEST to Conditional compilation symbols field
Run your code and enjoy :)
add a comment |
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:
- Go to Your project -> Properties -> Build
- Switch configuration to Test
- Enter TEST to Conditional compilation symbols field
Run your code and enjoy :)
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:
- Go to Your project -> Properties -> Build
- Switch configuration to Test
- Enter TEST to Conditional compilation symbols field
Run your code and enjoy :)
answered Jul 15 '16 at 12:49
eldrex
537
537
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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