Hi guys, I’ve got a Project in Visual Studio that builds it’s own dll (standard C# class Library) added to a unity solution (because we can these days).
Now I want to use unity’s built-in preprocessor directives: these ones Preprocessor Directives.
The only issue is they aren’t defined in my C# project even if I reference a Unity project.
The goal here is to insert the dll into a unity project and be able to compile parts of the code for specific versions of Unity.
Pre processor directives as the name suggests are interpreted by the preprocessor of the compiler. Therefore once the code is compiled they do not exist anymore. The pre processor literally removes things that are in a conditional code block from the source files before they are compiled. Since you compiled your DLL already there is no way to change anything in the code. You would need to compile seperate assemblies for the different versions you want to support. You have to set the defines manually in your Visual Studio project to control which version you are compiling.
So, you can write a function for each version, applying to each, a conditional attribute with its own unique “Version” pragma. Then, in your public/primary function, call them all: one will actually execute (assuming you have (only) one of the unique pragmas defined in the client project).