oleg-shilo / cs-script

C# scripting platform
http://www.cs-script.net
MIT License
1.62k stars 235 forks source link

add compiler option -define:DEBUG if debug is set #295

Closed rp0815 closed 2 years ago

rp0815 commented 2 years ago

If the script is compiled with debug-mode the option -define:DEBUG should be added. This will activate all Debug.* methods (Debug.WriteLine() and so on)

oleg-shilo commented 2 years ago

Hosted

CSScript.EvaluatorConfig.CompilerOptions = "...";

CLI https://github.com/oleg-shilo/cs-script/wiki/CS-Script---Command-Line-Interface#-cooptions

rp0815 commented 2 years ago

Yepp, I found EvaluatorConfig.CompilerOptions. I used it to set /preferreduilang:en-US to get english output from the compiler. I just mentioned 'cause it would be nice to set this option in the evaluator depending on the debug mode. Well, this is a minor implementation detail, since this can be set from outside of cs-script.

oleg-shilo commented 2 years ago

And of course, you can resort to the dedicated config member:

#if DEBUG
    CSScript.EvaluatorConfig.DebugBuild = true;
#endif

But when it comes to the idea of the default values of the EvaluatorConfig depending on #if DEBUG, I am not convinced it is good API practice. The behaviour of any API should not depend on the type of the build. I understand, it can be debated :) Sorry. But the code above probably is an adequate alternative.

rp0815 commented 2 years ago

CSScript.EvaluatorConfig.DebugBuild = true; is exactly what I did in my code. The problem seems to be that nowhere in the evaluator code the option /define:DEBUG is set. As far as I have seen only TRACE, NETCORE and CS_SCRIPT are set as define.

Compiling a code file with /define:DEBUG will make Debug. methods functional. Compiling without this define will set these methods to void, thus doing nothing. I guess it is good convention to write code using e.g. Debug.WriteLine() for debug which automatically will disappear when compiling for release. So of course there are plenty of code files with Debug. at our site.

oleg-shilo commented 2 years ago

Agree, this is a defect.

DebugBuild should not only trigger the debug symbols inclusion but also DEBUG compilation symbol set as well. Changing the issue to 'bug'.

Please use CompilerOptions as a temporary workaround.

oleg-shilo commented 2 years ago

Done. Will be available in the very next release. Now CSScript.EvaluatorConfig.DebugBuild = true; also sets DEBUG conditional compilation symbol

rp0815 commented 2 years ago

This works well in 4.4.5. Thank you.