-
Notifications
You must be signed in to change notification settings - Fork 265
Using preprocessor directives with Roslyn / SourceCodeKind.Regular #448
Description
Hello,
We used to be a able to do the following when our scripts where targeting .Net Framework 4:
//css_precompiler ../precompilers/plugin_precompiler
And inside plugin_precompiler, do something like this:
public class Plugin_Precompiler
{
public static bool Compile(ref string code, string scriptFile, bool isPrimaryScript, Hashtable context)
{
code = "#define MY_DEFINE" + System.Environment.NewLine + code
return true;
}
}And this worked pretty well. It also supported imports.
Now that we moved to .NET 9 and using CSScriptLib with the Roslyn evaluator, this functionnality does not seem to work anymore. We looked into trying to pass the defines via some options, we couldn't find anything. The closest we found was some commented out code Evaluator.Roslyn.cs with the following comment: "unfortunately the next code block will not work. Roslyn scripting fails to create compilation if ParseOptions are set".
We tried injecting the #define at the top of the script file. It works, but as soon as there are imports that use said define, the compilation fails:
CSScriptLib.CompilerException: <script>(1,2): error CS1032: Cannot define/undefine preprocessor symbols after first token in file.
We're out of ideas on how to solve this issue. Anyone knows how this can be solved?