@@ -56,49 +56,27 @@ public void Compile()
5656 rspPath = "Temp/" + Path . GetFileName ( rspPath ) ;
5757 File . WriteAllText ( rspPath , rsp ) ;
5858
59- // Detect csc tool exe.
60- var mono = Application . platform != RuntimePlatform . WindowsEditor ;
61- var cscToolExe = appContents + "/Tools/RoslynNet46/csc.exe" . Replace ( '/' , Path . DirectorySeparatorChar ) ;
62- if ( ! File . Exists ( cscToolExe ) )
63- cscToolExe = appContents + "/Tools/Roslyn/csc.exe" . Replace ( '/' , Path . DirectorySeparatorChar ) ;
64- if ( ! File . Exists ( cscToolExe ) )
65- {
66- cscToolExe = appContents + "/Tools/Roslyn/csc" . Replace ( '/' , Path . DirectorySeparatorChar ) ;
67- mono = false ;
68- }
59+ var compilerInfo = CompilerInfo . GetInstalledInfo ( "Microsoft.Net.Compilers.Toolset.3.5.0" ) ;
6960
70- // Create compilation process.
71- var psi = new ProcessStartInfo
72- {
73- CreateNoWindow = true ,
74- UseShellExecute = false ,
75- RedirectStandardError = true ,
76- RedirectStandardOutput = true ,
77- } ;
61+ // Setup recompile process.
62+ var psi = new ProcessStartInfo ( ) ;
63+ compilerInfo . Setup ( psi , rspPath , Application . platform ) ;
7864
79- if ( ! mono )
80- {
81- psi . FileName = Path . GetFullPath ( cscToolExe ) ;
82- psi . Arguments = "/shared /noconfig @" + rspPath ;
83- }
84- else
65+ using ( var program = Type . GetType ( "UnityEditor.Utils.Program, UnityEditor" ) . New ( psi ) as IDisposable )
8566 {
86- psi . FileName = Path . Combine ( appContents , "MonoBleedingEdge/bin/mono" ) ;
87- psi . Arguments = cscToolExe + " /noconfig @" + rspPath ;
88- }
89-
90- // Start compilation process.
91- var assemblyName = Path . GetFileName ( dllPath ) ;
92- Debug . LogFormat ( "<b>Recompile [{0}]: start compilation.</b>\n command = {1} {2}\n " , assemblyName , psi . FileName , psi . Arguments ) ;
93- var p = Process . Start ( psi ) ;
94- p . Exited += ( _ , __ ) =>
95- {
96- if ( p . ExitCode == 0 )
67+ // Start recompile.
68+ var assemblyName = Path . GetFileName ( dllPath ) ;
69+ Debug . LogFormat ( "<b>Recompile [{0}]: start compilation.</b>\n command = {1} {2}\n " , assemblyName , psi . FileName , psi . Arguments ) ;
70+ program . Call ( "Start" ) ;
71+ program . Call ( "WaitForExit" ) ;
72+
73+ // Check outputs.
74+ var exitCode = ( int ) program . Get ( "ExitCode" ) ;
75+ if ( exitCode == 0 )
9776 Debug . LogFormat ( "<b><color=#22aa22>Recompile [{0}]: success.</color></b>" , assemblyName ) ;
9877 else
99- Debug . LogErrorFormat ( "<b><color=#aa2222>Recompile [{0}]: failure.</color></b>\n {1}\n \n {2}" , assemblyName , p . StandardError . ReadToEnd ( ) , p . StandardOutput . ReadToEnd ( ) ) ;
100- } ;
101- p . EnableRaisingEvents = true ;
78+ Debug . LogErrorFormat ( "<b><color=#aa2222>Recompile [{0}]: failure.</color></b>\n {1}" , assemblyName , program . Call ( "GetAllOutput" ) ) ;
79+ }
10280 }
10381 }
10482
@@ -137,7 +115,6 @@ private static void InitializeOnLoadMethod()
137115
138116 private static void RequestToRecompileIfNeeded ( string assemblyPath , CompilerMessage [ ] messages )
139117 {
140- Debug . Log ( ">>>>" + assemblyPath ) ;
141118 // Skip: Compile error.
142119 if ( messages . Any ( x => x . type == CompilerMessageType . Error ) ) return ;
143120
0 commit comments