Fix can't always find additional system references under mono

This commit is contained in:
UnknownShadow200 2025-08-02 07:54:09 +10:00
parent 86af8c8f27
commit 128533a01f

View File

@ -66,10 +66,14 @@ namespace MCGalaxy.Modules.Compiling
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.Append("/t:library "); sb.Append("/t:library ");
// /noconfig disables compiler adding a list of default additional system libraries
// TODO: should this be left enabled?
sb.Append("/utf8output /noconfig /fullpaths "); sb.Append("/utf8output /noconfig /fullpaths ");
AddCoreAssembly(sb); AddCoreAssembly(sb);
AddReferencedAssemblies(sb, referencedAssemblies); AddReferencedAssemblies(sb, referencedAssemblies);
dstPath = Path.GetFullPath(dstPath);
sb.AppendFormat("/out:{0} ", Quote(dstPath)); sb.AppendFormat("/out:{0} ", Quote(dstPath));
sb.Append("/D:DEBUG /debug+ /optimize- "); sb.Append("/D:DEBUG /debug+ /optimize- ");
@ -173,12 +177,13 @@ namespace MCGalaxy.Modules.Compiling
internal class ClassicCSharpCompiler : CommandLineCompiler internal class ClassicCSharpCompiler : CommandLineCompiler
{ {
protected override void AddCoreAssembly(StringBuilder sb) { protected override void AddCoreAssembly(StringBuilder sb) {
string coreAssemblyFileName = typeof(object).Assembly.Location; // When running under mono, disabling referencing the standard library results
// in the compiler failing to find system referenced libraries (e.g. System.dll)
if (!string.IsNullOrEmpty(coreAssemblyFileName)) { // Not a huge deal, since AFAIK mono only supports running on one runtime anyways
sb.Append("/nostdlib+ "); // TODO: Investigate why this used to previously work fine with CodeDomProvider
sb.AppendFormat("/R:{0} ", Quote(coreAssemblyFileName)); if (Server.RunningOnMono()) return;
}
base.AddCoreAssembly(sb);
} }
protected override void AddReferencedAssemblies(StringBuilder sb, List<string> referenced) { protected override void AddReferencedAssemblies(StringBuilder sb, List<string> referenced) {