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(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)); } }
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)); } }
static MSBuildSdks() { TargetRuntime runtime = IdeApp.Preferences.DefaultTargetRuntime; string binPath = runtime.GetMSBuildBinPath("15.0"); if (binPath != null) { string sdksPath = Path.Combine(binPath, "Sdks"); if (Directory.Exists(sdksPath)) { Installed = true; MSBuildSDKsPath = sdksPath; } } }
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 { 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, StringComparison.Ordinal)) { 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.SetCulture(GettextCatalog.UICulture); engine.SetGlobalProperties(GetCoreGlobalProperties(solutionFile)); foreach (var gpp in globalPropertyProviders) { builder.SetGlobalProperties(gpp.GetGlobalProperties()); } 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)); } }
public string GetBinPath() => target.GetMSBuildBinPath(tvString);
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)); } }
internal static RemoteProjectBuilder GetProjectBuilder(TargetRuntime runtime, string minToolsVersion, string file, string solutionFile) { lock (builders) { //attempt to use 14.0 builder first if available string toolsVersion = "14.0"; string binDir = runtime.GetMSBuildBinPath("14.0"); if (binDir == null) { toolsVersion = "12.0"; 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)); } }