I’ve been working on updating an application for several months, and it uses an embedded C# sharp compiler to script things at runtime. The prior team packaged the build with what looks like the full mono 2.6 library, with extra folders like app/ and bin/ and lib/ all containing mono related files in addition to the typical Unity Application build structure. It all runs in the Unity Editor. I don’t know one goes about including the full Mono in a Unity build, so I tried to do a build of the updated application after tweaking some settings to conform it.
Basically it can’t compile C# scripts on build because it says it can’t find /net_4_x/mcs.exe. I need it to use what we have: /net_2_0/gmcs.exe – not sure where or how you set that target
Do I need to build the project with MonoDevelop itself in order to link it properly?
Here’s the Error I get on build from the embedded compiler, if I could get it to target the /net_2_0/ folder we have, instead of the /net_4_x/ folder then it might just work:
-- C# SCRIPT COMPILER ERROR: (0,0): error : Cannot open assembly 'C:\Users\Desktop\StudioWin3.0bMonoDllTest\app\lib\net_4_x\mcs.exe': No such file or directory.
-- STACK TRACE: at csscript.CSExecutor.M1TEbId8Ka (System.CodeDom.Compiler.CompilerResults , System.CodeDom.Compiler.CompilerParameters , CSScriptLibrary.ScriptParser , System.String , System.String ) [0x001d8] in <ea376207bd074618b3fd9bee46d2ebe4>:0
at csscript.CSExecutor.WrbE3iV53m (System.String ) [0x006e7] in <ea376207bd074618b3fd9bee46d2ebe4>:0
at csscript.CSExecutor.q1qEnmThTi (System.String , System.String , System.Boolean ) [0x000f4] in <ea376207bd074618b3fd9bee46d2ebe4>:0
at CSScriptLibrary.CSScript.Load (System.String scriptFile, System.String assemblyFile, System.Boolean debugBuild, System.String[ ] refAssemblies) [0x0012d] in <ea376207bd074618b3fd9bee46d2ebe4>:0
at CSScriptLibrary.CSScript.LoadCode (System.String scriptText, System.String tempFileExtension, System.String assemblyFile, System.Boolean debugBuild, System.String[ ] refAssemblies) [0x000e3] in <ea376207bd074618b3fd9bee46d2ebe4>:0
at CSScriptLibrary.CSScript.LoadCode (System.String scriptText, System.String assemblyFile, System.Boolean debugBuild, System.String[ ] refAssemblies) [0x00001] in <ea376207bd074618b3fd9bee46d2ebe4>:0
at CSScriptLibrary.CSScript.LoadCode (System.String scriptText, System.String[ ] refAssemblies) [0x00001] in <ea376207bd074618b3fd9bee46d2ebe4>:0
at Core.X6QGRsyafC (System.String , System.Collections.ArrayList , System.String , System.String[ ] ) [0x0007c] in <ea376207bd074618b3fd9bee46d2ebe4>:0
-- END STACK TRACE
3:01 PM
I’ve downloaded the .net 2.1 SDKs and runtimes for Visual Studio 2019, I’ve also mimicked the prior directory structure from the old version of our application build. The Unity Project targets .net 2.1 in the player settings. I’ve modified my Assembly-CSharp.csproj to have a target framework of netstandard2.1. I get no errors when I open Visual Studio 2019 having made those changes. No errors in my Unity console about it either.
I have set scripting defines in my Unity Player Settings for
CS_SCRIPT and NET_2_1
I’m running Unity 2021.3.2f1, Windows 10. Target build platform is Windows for now.
I’ve also tried to suss out whether I need to change any config files anywhere or if there’s a specific .rsp I need to name. Not sure what to do there.
It seems like if I just change a parameter somewhere, the compiler would target a different .net version and go to the other directory.
I’ve read through some solutions on GitHub by Aeroson and follow ups from there, but it seems like I don’t need to reinvent the wheel although it’s a similar problem. I have all the files I need, it’s just targeting the wrong .exe version in the wrong folder, right next to the one I want.
https://github.com/aeroson/mcs-ICodeCompiler
https://www.arcturuscollective.com/archives/22
I’ve tried taking a fresh Mono install and adding the /net_4_x/ folder, it comes back with a different error, at least I know it’s trying:
-- C# SCRIPT COMPILER ERROR: Compiler failed to produce the assembly. Output: ''
-- STACK TRACE: at Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[ ] fileNames) [0x0031f] in <6d7c4c8dd3624dc596686fb7270ae1e6>:0
at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromFileBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[ ] fileNames) [0x0003a] in <6d7c4c8dd3624dc596686fb7270ae1e6>:0
at csscript.CSExecutor.D65EYDFnlh (System.CodeDom.Compiler.ICodeCompiler , System.CodeDom.Compiler.CompilerParameters , System.String[ ] ) [0x0002f] in <ea376207bd074618b3fd9bee46d2ebe4>:0
at csscript.CSExecutor.WrbE3iV53m (System.String ) [0x00239] in <ea376207bd074618b3fd9bee46d2ebe4>:0
at csscript.CSExecutor.q1qEnmThTi (System.String , System.String , System.Boolean ) [0x000f4] in <ea376207bd074618b3fd9bee46d2ebe4>:0
at CSScriptLibrary.CSScript.Load (System.String scriptFile, System.String assemblyFile, System.Boolean debugBuild, System.String[ ] refAssemblies) [0x0012d] in <ea376207bd074618b3fd9bee46d2ebe4>:0
at CSScriptLibrary.CSScript.LoadCode (System.String scriptText, System.String tempFileExtension, System.String assemblyFile, System.Boolean debugBuild, System.String[ ] refAssemblies) [0x000e3] in <ea376207bd074618b3fd9bee46d2ebe4>:0
at CSScriptLibrary.CSScript.LoadCode (System.String scriptText, System.String assemblyFile, System.Boolean debugBuild, System.String[ ] refAssemblies) [0x00001] in <ea376207bd074618b3fd9bee46d2ebe4>:0
at CSScriptLibrary.CSScript.LoadCode (System.String scriptText, System.String[ ] refAssemblies) [0x00001] in <ea376207bd074618b3fd9bee46d2ebe4>:0
at CognitiveCode.Silvia.Core.SilviaCS.X6QGRsyafC (System.String , System.Collections.ArrayList , System.String , System.String[ ] ) [0x0007c] in <ea376207bd074618b3fd9bee46d2ebe4>:0
-- END STACK TRACE