internal static void ReleaseProjectBuilder (RemoteBuildEngine engine) { lock (builders) { if (--engine.ReferenceCount != 0) return; builders.Remove (builders.First (kvp => kvp.Value == engine).Key); } engine.Dispose (); }
internal static void ReleaseProjectBuilder (RemoteBuildEngine engine) { lock (builders) { if (engine.ReferenceCount > 0) { if (--engine.ReferenceCount == 0) { engine.ReleaseTime = DateTime.Now.AddSeconds (3); ScheduleProjectBuilderCleanup (engine.ReleaseTime.AddMilliseconds (500)); } } } }
internal static RemoteProjectBuilder GetProjectBuilder (TargetRuntime runtime, string minToolsVersion, string file, string solutionFile) { lock (builders) { //attempt to use 12.0 builder first if available string toolsVersion = "12.0"; string binDir = runtime.GetMSBuildBinPath ("12.0"); if (binDir == null) { //fall back to 4.0, we know it's always available toolsVersion = "4.0"; } //check the ToolsVersion we found can handle the project Version tv, mtv; if (Version.TryParse (toolsVersion, out tv) && Version.TryParse (minToolsVersion, out mtv) && tv < mtv) { string error = null; if (runtime is MsNetTargetRuntime && minToolsVersion == "12.0") error = "MSBuild 2013 is not installed. Please download and install it from " + "http://www.microsoft.com/en-us/download/details.aspx?id=40760"; throw new InvalidOperationException (error ?? string.Format ( "Runtime '{0}' does not have MSBuild '{1}' ToolsVersion installed", runtime.Id, toolsVersion) ); } //one builder per solution string builderKey = runtime.Id + " # " + solutionFile; RemoteBuildEngine builder; if (builders.TryGetValue (builderKey, out builder)) { builder.ReferenceCount++; return new RemoteProjectBuilder (file, builder); } //always start the remote process explicitly, even if it's using the current runtime and fx //else it won't pick up the assembly redirects from the builder exe var exe = GetExeLocation (runtime, toolsVersion); MonoDevelop.Core.Execution.RemotingService.RegisterRemotingChannel (); var pinfo = new ProcessStartInfo (exe) { UseShellExecute = false, CreateNoWindow = true, RedirectStandardError = true, RedirectStandardInput = true, }; runtime.GetToolsExecutionEnvironment ().MergeTo (pinfo); Process p = null; try { IBuildEngine engine; if (!runLocal) { p = runtime.ExecuteAssembly (pinfo); // The builder app will write the build engine reference // after reading the process id from the standard input ManualResetEvent ev = new ManualResetEvent (false); string responseKey = "[MonoDevelop]"; string sref = null; p.ErrorDataReceived += (sender, e) => { if (e.Data == null) return; if (e.Data.StartsWith (responseKey, StringComparison.Ordinal)) { sref = e.Data.Substring (responseKey.Length); ev.Set (); } else Console.WriteLine (e.Data); }; p.BeginErrorReadLine (); p.StandardInput.WriteLine (Process.GetCurrentProcess ().Id.ToString ()); if (!ev.WaitOne (TimeSpan.FromSeconds (5))) throw new Exception ("MSBuild process could not be started"); byte[] data = Convert.FromBase64String (sref); MemoryStream ms = new MemoryStream (data); BinaryFormatter bf = new BinaryFormatter (); engine = (IBuildEngine)bf.Deserialize (ms); } else { var asm = System.Reflection.Assembly.LoadFrom (exe); var t = asm.GetType ("MonoDevelop.Projects.Formats.MSBuild.BuildEngine"); engine = (IBuildEngine)Activator.CreateInstance (t); } engine.SetCulture (GettextCatalog.UICulture); engine.SetGlobalProperties (GetCoreGlobalProperties (solutionFile)); foreach (var gpp in globalPropertyProviders) engine.SetGlobalProperties (gpp.GetGlobalProperties ()); builder = new RemoteBuildEngine (p, engine); } catch { if (p != null) { try { p.Kill (); } catch { } } throw; } builders [builderKey] = builder; builder.ReferenceCount = 1; builder.Disconnected += delegate { lock (builders) builders.Remove (builderKey); }; return new RemoteProjectBuilder (file, builder); } }
public void Dispose () { if (engine != null) { if (builder != null) engine.UnloadProject (builder); MSBuildProjectService.ReleaseProjectBuilder (engine); GC.SuppressFinalize (this); engine = null; builder = null; } }
public static RemoteProjectBuilder GetProjectBuilder (TargetRuntime runtime, TargetFramework fx, string file) { lock (builders) { string binDir = runtime.GetMSBuildBinPath (fx); RemoteBuildEngine builder; if (builders.TryGetValue (runtime, out builder)) { builder.ReferenceCount++; return new RemoteProjectBuilder (file, binDir, builder); } if (runtime.IsRunning) { if (currentBuildEngine == null) currentBuildEngine = new RemoteBuildEngine (null, new BuildEngine ()); return new RemoteProjectBuilder (file, binDir, currentBuildEngine); } else { MonoDevelop.Core.Execution.RemotingService.RegisterRemotingChannel (); string exe = typeof(ProjectBuilder).Assembly.Location; ProcessStartInfo pinfo = new ProcessStartInfo (exe); runtime.GetToolsExecutionEnvironment (fx).MergeTo (pinfo); pinfo.UseShellExecute = false; pinfo.RedirectStandardError = true; pinfo.RedirectStandardInput = true; Process p = null; try { p = runtime.ExecuteAssembly (pinfo, fx); p.StandardInput.WriteLine (Process.GetCurrentProcess ().Id.ToString ()); string sref = p.StandardError.ReadLine (); byte[] data = Convert.FromBase64String (sref); MemoryStream ms = new MemoryStream (data); BinaryFormatter bf = new BinaryFormatter (); builder = new RemoteBuildEngine (p, (IBuildEngine) bf.Deserialize (ms)); } catch { if (p != null) { try { p.Kill (); } catch { } } throw; } } builders [runtime] = builder; builder.ReferenceCount = 1; return new RemoteProjectBuilder (file, binDir, builder); } }
public static RemoteProjectBuilder GetProjectBuilder (TargetRuntime runtime, string minToolsVersion, string file, string solutionFile) { lock (builders) { //attempt to use 12.0 builder first if available string toolsVersion = "12.0"; string binDir = runtime.GetMSBuildBinPath ("12.0"); if (binDir == null) { //fall back to 4.0, we know it's always available toolsVersion = "4.0"; } //check the ToolsVersion we found can handle the project Version tv, mtv; if (Version.TryParse (toolsVersion, out tv) && Version.TryParse (minToolsVersion, out mtv) && tv < mtv) { string error = null; if (runtime is MsNetTargetRuntime && minToolsVersion == "12.0") error = "MSBuild 2013 is not installed. Please download and install it from " + "http://www.microsoft.com/en-us/download/details.aspx?id=40760"; throw new InvalidOperationException (error ?? string.Format ( "Runtime '{0}' does not have MSBuild '{1}' ToolsVersion installed", runtime.Id, toolsVersion) ); } //one builder per solution string builderKey = runtime.Id + " # " + solutionFile; RemoteBuildEngine builder; if (builders.TryGetValue (builderKey, out builder)) { builder.ReferenceCount++; return new RemoteProjectBuilder (file, builder); } //always start the remote process explicitly, even if it's using the current runtime and fx //else it won't pick up the assembly redirects from the builder exe var exe = GetExeLocation (runtime, toolsVersion); MonoDevelop.Core.Execution.RemotingService.RegisterRemotingChannel (); var pinfo = new ProcessStartInfo (exe) { UseShellExecute = false, CreateNoWindow = true, RedirectStandardError = true, RedirectStandardInput = true, }; runtime.GetToolsExecutionEnvironment ().MergeTo (pinfo); Process p = null; try { p = runtime.ExecuteAssembly (pinfo); p.StandardInput.WriteLine (Process.GetCurrentProcess ().Id.ToString ()); string responseKey = "[MonoDevelop]"; string sref; while (true) { sref = p.StandardError.ReadLine (); if (sref.StartsWith (responseKey)) { sref = sref.Substring (responseKey.Length); break; } } byte[] data = Convert.FromBase64String (sref); MemoryStream ms = new MemoryStream (data); BinaryFormatter bf = new BinaryFormatter (); var engine = (IBuildEngine)bf.Deserialize (ms); engine.Initialize (solutionFile, GettextCatalog.UICulture); builder = new RemoteBuildEngine (p, engine); } catch { if (p != null) { try { p.Kill (); } catch { } } throw; } builders [builderKey] = builder; builder.ReferenceCount = 1; return new RemoteProjectBuilder (file, builder); } }
internal RemoteProjectBuilder (string file, RemoteBuildEngine engine) { this.file = file; this.engine = engine; builder = engine.LoadProject (file); referenceCache = new Dictionary<string, string[]> (); }
public static RemoteProjectBuilder GetProjectBuilder (TargetRuntime runtime, string toolsVersion, string file, string solutionFile) { lock (builders) { string binDir = runtime.GetMSBuildBinPath (toolsVersion); if (binDir == null) { string error = null; if (runtime is MsNetTargetRuntime) { if (toolsVersion == "12.0") { error = "MSBuild 2013 is not installed. Please download and install it from " + "http://www.microsoft.com/en-us/download/details.aspx?id=40760"; } }; throw new InvalidOperationException (error ?? string.Format ( "Runtime '{0}' does not have MSBuild '{1}' ToolsVersion installed", runtime.Id, toolsVersion) ); } string builderKey = runtime.Id + " " + toolsVersion; RemoteBuildEngine builder; if (builders.TryGetValue (builderKey, out builder)) { builder.ReferenceCount++; return new RemoteProjectBuilder (file, solutionFile, binDir, builder); } //always start the remote process explicitly, even if it's using the current runtime and fx //else it won't pick up the assembly redirects from the builder exe var exe = GetExeLocation (runtime, toolsVersion); MonoDevelop.Core.Execution.RemotingService.RegisterRemotingChannel (); var pinfo = new ProcessStartInfo (exe) { UseShellExecute = false, CreateNoWindow = true, RedirectStandardError = true, RedirectStandardInput = true, }; runtime.GetToolsExecutionEnvironment ().MergeTo (pinfo); Process p = null; try { p = runtime.ExecuteAssembly (pinfo); p.StandardInput.WriteLine (Process.GetCurrentProcess ().Id.ToString ()); string sref = p.StandardError.ReadLine (); byte[] data = Convert.FromBase64String (sref); MemoryStream ms = new MemoryStream (data); BinaryFormatter bf = new BinaryFormatter (); var engine = (IBuildEngine)bf.Deserialize (ms); engine.SetUICulture (GettextCatalog.UICulture); builder = new RemoteBuildEngine (p, engine); } catch { if (p != null) { try { p.Kill (); } catch { } } throw; } builders [builderKey] = builder; builder.ReferenceCount = 1; return new RemoteProjectBuilder (file, solutionFile, binDir, builder); } }
public static RemoteProjectBuilder GetProjectBuilder (TargetRuntime runtime, string toolsVersion, string file) { lock (builders) { var toolsFx = Runtime.SystemAssemblyService.GetTargetFramework (toolsVersion); string binDir = runtime.GetMSBuildBinPath (toolsFx); if (!runtime.IsInstalled (toolsFx)) throw new InvalidOperationException (string.Format ( "Runtime '{0}' cannot be used to build MSBuild '{1}' format projects", runtime.Id, toolsVersion)); string builderKey = runtime.Id + " " + toolsVersion; RemoteBuildEngine builder; if (builders.TryGetValue (builderKey, out builder)) { builder.ReferenceCount++; return new RemoteProjectBuilder (file, binDir, builder); } if (runtime.IsRunning && toolsVersion == REFERENCED_MSBUILD_TOOLS) { if (currentBuildEngine == null) currentBuildEngine = new RemoteBuildEngine (null, new BuildEngine ()); return new RemoteProjectBuilder (file, binDir, currentBuildEngine); } else { string exe = GetExeLocation (toolsVersion); MonoDevelop.Core.Execution.RemotingService.RegisterRemotingChannel (); ProcessStartInfo pinfo = new ProcessStartInfo (exe); runtime.GetToolsExecutionEnvironment (toolsFx).MergeTo (pinfo); pinfo.UseShellExecute = false; pinfo.RedirectStandardError = true; pinfo.RedirectStandardInput = true; Process p = null; try { p = runtime.ExecuteAssembly (pinfo); p.StandardInput.WriteLine (Process.GetCurrentProcess ().Id.ToString ()); string sref = p.StandardError.ReadLine (); byte[] data = Convert.FromBase64String (sref); MemoryStream ms = new MemoryStream (data); BinaryFormatter bf = new BinaryFormatter (); builder = new RemoteBuildEngine (p, (IBuildEngine) bf.Deserialize (ms)); } catch { if (p != null) { try { p.Kill (); } catch { } } throw; } } builders [builderKey] = builder; builder.ReferenceCount = 1; return new RemoteProjectBuilder (file, binDir, builder); } }
internal RemoteProjectBuilder (string file, string solutionFile, string binPath, RemoteBuildEngine engine) { this.engine = engine; builder = engine.LoadProject (file, solutionFile, binPath); }
internal static RemoteProjectBuilder GetProjectBuilder(TargetRuntime runtime, string minToolsVersion, string file, string solutionFile) { lock (builders) { //attempt to use 12.0 builder first if available string toolsVersion = "12.0"; string binDir = runtime.GetMSBuildBinPath("12.0"); if (binDir == null) { //fall back to 4.0, we know it's always available toolsVersion = "4.0"; } //check the ToolsVersion we found can handle the project Version tv, mtv; if (Version.TryParse(toolsVersion, out tv) && Version.TryParse(minToolsVersion, out mtv) && tv < mtv) { string error = null; if (runtime is MsNetTargetRuntime && minToolsVersion == "12.0") { error = "MSBuild 2013 is not installed. Please download and install it from " + "http://www.microsoft.com/en-us/download/details.aspx?id=40760"; } throw new InvalidOperationException(error ?? string.Format( "Runtime '{0}' does not have MSBuild '{1}' ToolsVersion installed", runtime.Id, toolsVersion) ); } //one builder per solution string builderKey = runtime.Id + " # " + solutionFile; RemoteBuildEngine builder; if (builders.TryGetValue(builderKey, out builder)) { builder.ReferenceCount++; return(new RemoteProjectBuilder(file, builder)); } //always start the remote process explicitly, even if it's using the current runtime and fx //else it won't pick up the assembly redirects from the builder exe var exe = GetExeLocation(runtime, toolsVersion); MonoDevelop.Core.Execution.RemotingService.RegisterRemotingChannel(); var pinfo = new ProcessStartInfo(exe) { UseShellExecute = false, CreateNoWindow = true, RedirectStandardError = true, RedirectStandardInput = true, }; runtime.GetToolsExecutionEnvironment().MergeTo(pinfo); Process p = null; try { IBuildEngine engine; if (!runLocal) { p = runtime.ExecuteAssembly(pinfo); // The builder app will write the build engine reference // after reading the process id from the standard input ManualResetEvent ev = new ManualResetEvent(false); string responseKey = "[MonoDevelop]"; string sref = null; p.ErrorDataReceived += (sender, e) => { if (e.Data.StartsWith(responseKey, StringComparison.Ordinal)) { sref = e.Data.Substring(responseKey.Length); ev.Set(); } else { Console.WriteLine(e.Data); } }; p.BeginErrorReadLine(); p.StandardInput.WriteLine(Process.GetCurrentProcess().Id.ToString()); if (!ev.WaitOne(TimeSpan.FromSeconds(5))) { throw new Exception("MSBuild process could not be started"); } byte[] data = Convert.FromBase64String(sref); MemoryStream ms = new MemoryStream(data); BinaryFormatter bf = new BinaryFormatter(); engine = (IBuildEngine)bf.Deserialize(ms); } else { var asm = System.Reflection.Assembly.LoadFrom(exe); var t = asm.GetType("MonoDevelop.Projects.Formats.MSBuild.BuildEngine"); engine = (IBuildEngine)Activator.CreateInstance(t); } engine.SetCulture(GettextCatalog.UICulture); engine.SetGlobalProperties(GetCoreGlobalProperties(solutionFile)); foreach (var gpp in globalPropertyProviders) { engine.SetGlobalProperties(gpp.GetGlobalProperties()); } builder = new RemoteBuildEngine(p, engine); } catch { if (p != null) { try { p.Kill(); } catch { } } throw; } builders [builderKey] = builder; builder.ReferenceCount = 1; builder.Disconnected += delegate { lock (builders) builders.Remove(builderKey); }; return(new RemoteProjectBuilder(file, builder)); } }
internal RemoteProjectBuilder(string file, RemoteBuildEngine engine) { this.engine = engine; builder = engine.LoadProject(file); referenceCache = new Dictionary <string, string[]> (); }
internal RemoteProjectBuilder(string file, RemoteBuildEngine engine) { this.engine = engine; builder = engine.LoadProject(file); }
public void Dispose () { if (!MSBuildProjectService.ShutDown && engine != null) { try { if (builder != null) engine.UnloadProject (builder); MSBuildProjectService.ReleaseProjectBuilder (engine); } catch { // Ignore } GC.SuppressFinalize (this); engine = null; builder = null; } }
public static RemoteProjectBuilder GetProjectBuilder (TargetRuntime runtime, string toolsVersion, string file) { lock (builders) { var toolsFx = Runtime.SystemAssemblyService.GetTargetFramework (new TargetFrameworkMoniker (toolsVersion)); string binDir = runtime.GetMSBuildBinPath (toolsFx); if (!runtime.IsInstalled (toolsFx)) throw new InvalidOperationException (string.Format ( "Runtime '{0}' does not have the MSBuild '{1}' framework installed", runtime.Id, toolsVersion)); string builderKey = runtime.Id + " " + toolsVersion; RemoteBuildEngine builder; if (builders.TryGetValue (builderKey, out builder)) { builder.ReferenceCount++; return new RemoteProjectBuilder (file, binDir, builder); } //always start the remote process explicitly, even if it's using the current runtime and fx //else it won't pick up the assembly redirects from the builder exe var exe = GetExeLocation (runtime, toolsVersion); MonoDevelop.Core.Execution.RemotingService.RegisterRemotingChannel (); var pinfo = new ProcessStartInfo (exe) { UseShellExecute = false, CreateNoWindow = true, RedirectStandardError = true, RedirectStandardInput = true, }; runtime.GetToolsExecutionEnvironment (toolsFx).MergeTo (pinfo); Process p = null; try { p = runtime.ExecuteAssembly (pinfo); p.StandardInput.WriteLine (Process.GetCurrentProcess ().Id.ToString ()); string sref = p.StandardError.ReadLine (); byte[] data = Convert.FromBase64String (sref); MemoryStream ms = new MemoryStream (data); BinaryFormatter bf = new BinaryFormatter (); builder = new RemoteBuildEngine (p, (IBuildEngine) bf.Deserialize (ms)); } catch { if (p != null) { try { p.Kill (); } catch { } } throw; } builders [builderKey] = builder; builder.ReferenceCount = 1; return new RemoteProjectBuilder (file, binDir, builder); } }
internal RemoteProjectBuilder (string file, RemoteBuildEngine engine) { this.engine = engine; builder = engine.LoadProject (file); }
public static RemoteProjectBuilder GetProjectBuilder(TargetRuntime runtime, string minToolsVersion, string file, string solutionFile) { lock (builders) { //attempt to use 12.0 builder first if available string toolsVersion = "12.0"; string binDir = runtime.GetMSBuildBinPath("12.0"); if (binDir == null) { //fall back to 4.0, we know it's always available toolsVersion = "4.0"; } //check the ToolsVersion we found can handle the project Version tv, mtv; if (Version.TryParse(toolsVersion, out tv) && Version.TryParse(minToolsVersion, out mtv) && tv < mtv) { string error = null; if (runtime is MsNetTargetRuntime && minToolsVersion == "12.0") { error = "MSBuild 2013 is not installed. Please download and install it from " + "http://www.microsoft.com/en-us/download/details.aspx?id=40760"; } throw new InvalidOperationException(error ?? string.Format( "Runtime '{0}' does not have MSBuild '{1}' ToolsVersion installed", runtime.Id, toolsVersion) ); } //one builder per solution string builderKey = runtime.Id + " # " + solutionFile; RemoteBuildEngine builder; if (builders.TryGetValue(builderKey, out builder)) { builder.ReferenceCount++; return(new RemoteProjectBuilder(file, builder)); } //always start the remote process explicitly, even if it's using the current runtime and fx //else it won't pick up the assembly redirects from the builder exe var exe = GetExeLocation(runtime, toolsVersion); MonoDevelop.Core.Execution.RemotingService.RegisterRemotingChannel(); var pinfo = new ProcessStartInfo(exe) { UseShellExecute = false, CreateNoWindow = true, RedirectStandardError = true, RedirectStandardInput = true, }; runtime.GetToolsExecutionEnvironment().MergeTo(pinfo); Process p = null; try { p = runtime.ExecuteAssembly(pinfo); p.StandardInput.WriteLine(Process.GetCurrentProcess().Id.ToString()); string responseKey = "[MonoDevelop]"; string sref; while (true) { sref = p.StandardError.ReadLine(); if (sref.StartsWith(responseKey)) { sref = sref.Substring(responseKey.Length); break; } } byte[] data = Convert.FromBase64String(sref); MemoryStream ms = new MemoryStream(data); BinaryFormatter bf = new BinaryFormatter(); var engine = (IBuildEngine)bf.Deserialize(ms); engine.Initialize(solutionFile, GettextCatalog.UICulture); builder = new RemoteBuildEngine(p, engine); } catch { if (p != null) { try { p.Kill(); } catch { } } throw; } builders [builderKey] = builder; builder.ReferenceCount = 1; return(new RemoteProjectBuilder(file, builder)); } }