@@ -51,16 +51,15 @@ private static int Compile(string[] args, Logger logger, Settings settings)
5151 var responseFile = args [ 0 ] ;
5252 var compilationOptions = File . ReadAllLines ( responseFile . TrimStart ( '@' ) ) ;
5353 var unityEditorDataDir = GetUnityEditorDataDir ( ) ;
54+ var monoProfileDir = GetMonoProfileDir ( compilationOptions ) ;
5455 var projectDir = Directory . GetCurrentDirectory ( ) ;
5556 var targetAssembly = compilationOptions . First ( line => line . StartsWith ( "-out:" ) ) . Substring ( 10 ) . Trim ( '\' ' ) ;
56- var monoProfile = compilationOptions . First ( line => line . StartsWith ( "-define:__UNITY_PROFILE__" ) ) . Substring ( 25 ) ;
57- if ( monoProfile == "2_0" ) monoProfile = "2.0" ;
5857
5958 logger ? . Append ( $ "CSharpCompilerWrapper.exe version: { Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version } ") ;
6059 logger ? . Append ( $ "Platform: { CurrentPlatform } ") ;
61- logger ? . Append ( $ "Mono profile: { monoProfile } ") ;
6260 logger ? . Append ( $ "Target assembly: { targetAssembly } ") ;
6361 logger ? . Append ( $ "Project directory: { projectDir } ") ;
62+ logger ? . Append ( $ "Mono profile directory: { monoProfileDir } ") ;
6463 logger ? . Append ( $ "Unity 'Data' or 'Frameworks' directory: { unityEditorDataDir } ") ;
6564
6665 if ( CurrentPlatform == Platform . Linux )
@@ -70,15 +69,15 @@ private static int Compile(string[] args, Logger logger, Settings settings)
7069 return - 1 ;
7170 }
7271
73- var compiler = CreateCompiler ( settings . Compiler , logger , CurrentPlatform , monoProfile , projectDir , compilationOptions , unityEditorDataDir ) ;
72+ var compiler = CreateCompiler ( settings . Compiler , logger , CurrentPlatform , monoProfileDir , projectDir , compilationOptions , unityEditorDataDir ) ;
7473
7574 logger ? . Append ( $ "Compiler: { compiler . Name } ") ;
7675 logger ? . Append ( "" ) ;
7776 logger ? . Append ( "- Compilation -----------------------------------------------" ) ;
7877 logger ? . Append ( "" ) ;
7978
8079 var stopwatch = Stopwatch . StartNew ( ) ;
81- var exitCode = compiler . Compile ( CurrentPlatform , monoProfile , unityEditorDataDir , responseFile ) ;
80+ var exitCode = compiler . Compile ( CurrentPlatform , monoProfileDir , unityEditorDataDir , responseFile ) ;
8281 stopwatch . Stop ( ) ;
8382
8483 logger ? . Append ( $ "Elapsed time: { stopwatch . ElapsedMilliseconds / 1000f : F2} sec") ;
@@ -108,19 +107,19 @@ private static int Compile(string[] args, Logger logger, Settings settings)
108107 return 0 ;
109108 }
110109
111- private static Compiler CreateCompiler ( CompilerType compilerType , Logger logger , Platform platform , string monoProfile , string projectDir , string [ ] compilationOptions , string unityEditorDataDir )
110+ private static Compiler CreateCompiler ( CompilerType compilerType , Logger logger , Platform platform , string monoProfileDir , string projectDir , string [ ] compilationOptions , string unityEditorDataDir )
112111 {
113112 var compilerDirectory = Path . Combine ( projectDir , LANGUAGE_SUPPORT_DIR ) ;
114113
115114 switch ( compilerType )
116115 {
117116 case CompilerType . Auto :
118- return FindSuitableCompiler ( logger , platform , monoProfile , projectDir , compilationOptions , unityEditorDataDir ) ;
117+ return FindSuitableCompiler ( logger , platform , monoProfileDir , projectDir , compilationOptions , unityEditorDataDir ) ;
119118
120119 case CompilerType . Mono3 :
121- var stockCompilerPath = monoProfile == "2.0"
120+ var stockCompilerPath = monoProfileDir . IndexOf ( "2.0" ) != - 1
122121 ? Path . Combine ( unityEditorDataDir , @"Mono/lib/mono/2.0/gmcs.exe" )
123- : Path . Combine ( unityEditorDataDir , @"Mono/lib/mono/" + monoProfile + "/ smcs.exe") ;
122+ : Path . Combine ( monoProfileDir , " smcs.exe") ;
124123 return new Mono30Compiler ( logger , stockCompilerPath ) ;
125124
126125 case CompilerType . Mono5 :
@@ -147,7 +146,7 @@ private static Compiler CreateCompiler(CompilerType compilerType, Logger logger,
147146 return null ;
148147 }
149148
150- private static Compiler FindSuitableCompiler ( Logger logger , Platform platform , string monoProfile , string projectDir , string [ ] compilationOptions , string unityEditorDataDir )
149+ private static Compiler FindSuitableCompiler ( Logger logger , Platform platform , string monoProfileDir , string projectDir , string [ ] compilationOptions , string unityEditorDataDir )
151150 {
152151 Compiler compiler = null ;
153152
@@ -190,9 +189,9 @@ private static Compiler FindSuitableCompiler(Logger logger, Platform platform, s
190189 if ( compiler == null )
191190 {
192191 // Using stock Mono C# 3.0 compiler
193- var stockCompilerPath = monoProfile == "2.0"
192+ var stockCompilerPath = monoProfileDir . IndexOf ( "2.0" ) != - 1
194193 ? Path . Combine ( unityEditorDataDir , @"Mono/lib/mono/2.0/gmcs.exe" )
195- : Path . Combine ( unityEditorDataDir , @"Mono/lib/mono/" + monoProfile + "/ smcs.exe") ;
194+ : Path . Combine ( monoProfileDir , " smcs.exe") ;
196195 compiler = new Mono30Compiler ( logger , stockCompilerPath ) ;
197196 }
198197
@@ -242,4 +241,17 @@ private static string GetUnityEditorDataDir()
242241 var path = monoPath . Substring ( 0 , index ) ;
243242 return path ;
244243 }
244+
245+ private static string GetMonoProfileDir ( string [ ] compilationOptions )
246+ {
247+ /* Looking for something like
248+ -r:"C:\Program Files\Unity\Editor\Data\Mono\lib\mono\unity\System.Xml.Linq.dll"
249+ or
250+ -r:'C:\Program Files\Unity\Editor\Data\Mono\lib\mono\unity\System.Xml.Linq.dll'
251+ */
252+ var reference = compilationOptions . First ( line => line . StartsWith ( "-r:" ) && line . Contains ( "System.Xml.Linq.dll" ) ) ;
253+ var systemXmlLinqPath = reference . Replace ( "'" , "" ) . Replace ( "\" " , "" ) . Substring ( 3 ) ;
254+ var profileDir = Path . GetDirectoryName ( systemXmlLinqPath ) ;
255+ return profileDir ;
256+ }
245257}
0 commit comments