Is it possible to call Unity’s script compiler from and editor script in order to compile a release version of Assembly-CSharp.dll? At the minute I am using the code dom to compile C# scripts into an assembly which is working OK but I would also like to support javascript compilation in my asset.
I know that unity keeps a version of Assembly-CSharp in the library folder which it re-compiles every time the scripts are modified (I assume js scripts are also included) but if you look at the assembly in a decompiler you can see that it references UnityEditor.dll and also editor pre-processor directives are compiled into the assembly so that is not an option.
From looking at the source of UnityEditor.dll I can see that there are namespaces called ‘UnityEditor.Scripting’ and ‘UnityEditor.Scripting.Compilers’ which look like they handle the script compilation in the editor but they are marked as internal. There is a method called ‘CreateCompilerInstance’ which looks like it would be perfect for my needs as it constructs the compiler based upon the file extension of the source files you provide. I know I can use reflection to access these internal types but that is hardly a safe option as it is subject to change at anytime which would break the asset.
Is there any way I can achieve this or am I stuck compiling C# only?
Thanks for the reply but I don’t need to compile at runtime. I need to compile a release version of Assembly-CSharp.dll at edit time. I can already do this using the code dom but I would like to use Unity’s compilers if possible to support javascript as well.
It’s depreciated officially, they removed the ability to create them from the editor in the next version of Unity. It will still work with Unity’s js for a few months but it is dead. Unity is looking for a good time to completely withdraw support including the Boo backend since the % of users using it is so tiny and it prevents good progress.
Just stick to supporting C#. Unity will tell you the same I suspect. There will be a blog post soon announcing the removal of Boo and Unity script (JS).
The UnityScript files does not go into Assembly-CSharp.dll, but into Assemly-UnityScript.dll. There’s a total of 12 dlls that are created by Unity, four for each language
Unity’s going to deprecate UnityScript too (as @hippocoder 's saying). So you don’t have to worry about supporting it. On the other hand, they’ve been saying for a while that they want to provide some kind of better control over assemblies - so we can define what assemblies scripts go into instead of having the four folder-based options. So it’s not a given that it’ll only be Assembly-CSharp.dll forever.