+ 6

Preprocessor directives

So in visual studio community DEBUG directive will be used if we are in debug, but does this mean that even exe will use everything that is in DEBUG? Now if we define wither one like TEST will this be active in release when we create exe to deploy too?

23rd Sep 2019, 5:24 PM
Dejan Dozet
Dejan Dozet - avatar
18 Respostas
+ 5
Hi de do.👋 What language are you using? Please add the language to the tags.
23rd Sep 2019, 5:40 PM
Manual
Manual - avatar
+ 5
de do C# does not have marcos like C/C++. You only have access to prrprocessors microsoft approved. Such as: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives/
23rd Sep 2019, 7:25 PM
Manual
Manual - avatar
+ 4
de do It that may be true. The issue is I felt that you were using C/C++. I felt the need to ask you for more detail, so I could know if I would be able to help you.
23rd Sep 2019, 6:45 PM
Manual
Manual - avatar
+ 3
I feel the same I would like him to clarify the matter. Well for now I going to do some work.
23rd Sep 2019, 7:16 PM
Manual
Manual - avatar
+ 3
~ swim ~ According to this you can use preprocessors in C#. You just cannot make your own macros.
23rd Sep 2019, 7:20 PM
Manual
Manual - avatar
+ 3
Just variables, no macros
23rd Sep 2019, 7:22 PM
Dejan Dozet
Dejan Dozet - avatar
+ 2
~ swim ~ I think you are right. I will find docs on the project configuration then
23rd Sep 2019, 7:04 PM
Manual
Manual - avatar
23rd Sep 2019, 7:06 PM
Manual
Manual - avatar
+ 2
Well it seems like he gave your answer the checkmark, maybe you have given the answer he wants? He has not said if we helped him find the solution or not.
23rd Sep 2019, 7:10 PM
Manual
Manual - avatar
+ 2
No, no need to give me the exact example of it, I just wanted to make clear that if custom defined directive will "cut" that part of code out (#else...), Thank you
23rd Sep 2019, 7:16 PM
Dejan Dozet
Dejan Dozet - avatar
23rd Sep 2019, 7:22 PM
Manual
Manual - avatar
+ 2
#if DEBUG Console.WriteLine("Debug version"); /*set boolean variable to true, to signal debug operations */ #endif he should use this
23rd Sep 2019, 7:27 PM
Manual
Manual - avatar
+ 2
~ swim ~ Same for me as well. I rarely use C#.
23rd Sep 2019, 7:28 PM
Manual
Manual - avatar
+ 2
And that you've said to me at the beginning of this conversation, it will stay there until I remove it in the both debug and release configuration. Thank you both for your help in this matter! I am not c# programmer too, but this time I've decided to finish one small project in it.
23rd Sep 2019, 7:44 PM
Dejan Dozet
Dejan Dozet - avatar
+ 1
~ swim ~ and if I define any other one it will be active in release mode too, will it be?
23rd Sep 2019, 6:20 PM
Dejan Dozet
Dejan Dozet - avatar
+ 1
Manual it is c#, but I think it is irrelevant what language it is, isn't it?
23rd Sep 2019, 6:29 PM
Dejan Dozet
Dejan Dozet - avatar
+ 1
~ swim ~ Gave you and example of preprocessors for C/C++. What you put in the tag. In Visual Studio "Release" and "Debug" are part of the project configurations not directive. Since it is still unclear if you are using the correct terms or not, I will guess what you are doing. In VS 2019 at the upper tab Below the Debug in C/C++. There is Debug x64 |> Local Windows Debugger. Is this what you are refering to?
23rd Sep 2019, 6:52 PM
Manual
Manual - avatar
+ 1
de do bool debug = false; #if DEBUG Console.WriteLine("Debug version"); /*set boolean variable to true, to signal debug operations */ debug = true; #endif This should work.
24th Sep 2019, 12:27 AM
Manual
Manual - avatar