31
31
using System.Runtime.Remoting;
32
32
using System.Collections.Generic;
33
33
using System.Collections;
34
using Microsoft.Build.BuildEngine;
35
using Microsoft.Build.Framework;
35
37
namespace MonoDevelop.Projects.Formats.MSBuild
37
39
public class BuildEngine: MarshalByRefObject, IBuildEngine
41
static AutoResetEvent wordDoneEvent = new AutoResetEvent (false);
42
static ThreadStart workDelegate;
43
static object workLock = new object ();
44
static Thread workThread;
45
static Exception workError;
39
47
ManualResetEvent doneEvent = new ManualResetEvent (false);
48
Dictionary<string,Engine> engines = new Dictionary<string, Engine> ();
41
50
public void Dispose ()
46
55
internal WaitHandle WaitHandle {
47
56
get { return doneEvent; }
50
59
public IProjectBuilder LoadProject (string file, string binDir)
52
return new ProjectBuilder (file, binDir);
61
return new ProjectBuilder (this, GetEngine (binDir), file);
55
64
public void UnloadProject (IProjectBuilder pb)
66
((ProjectBuilder)pb).Dispose ();
57
67
RemotingServices.Disconnect ((MarshalByRefObject) pb);
75
Engine GetEngine (string binDir)
79
if (!engines.TryGetValue (binDir, out engine)) {
80
engine = new Engine (binDir);
81
engine.GlobalProperties.SetProperty ("BuildingInsideVisualStudio", "true");
83
//we don't have host compilers in MD, and this is set to true by some of the MS targets
84
//which causes it to always run the CoreCompile task if BuildingInsideVisualStudio is also
85
//true, because the VS in-process compiler would take care of the deps tracking
86
engine.GlobalProperties.SetProperty ("UseHostCompilerIfAvailable", "false");
87
engines [binDir] = engine;
93
internal void UnloadProject (string file)
96
foreach (var engine in engines.Values) {
97
var loadedProj = engine.GetLoadedProject (file);
98
if (loadedProj != null)
99
engine.UnloadProject (loadedProj);
104
internal static void RunSTA (ThreadStart ts)
110
if (workThread == null) {
111
workThread = new Thread (STARunner);
112
workThread.SetApartmentState (ApartmentState.STA);
113
workThread.IsBackground = true;
117
// Awaken the existing thread
118
Monitor.Pulse (threadLock);
120
wordDoneEvent.WaitOne ();
122
if (workError != null)
123
throw new Exception ("MSBuild operation failed", workError);
126
static object threadLock = new object ();
128
static void STARunner ()
135
catch (Exception ex) {
138
wordDoneEvent.Set ();
140
while (Monitor.Wait (threadLock, 60000));
b'\\ No newline at end of file'