/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { string message = string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.GetType().FullName); string title = "LaunchDebugger"; // Show a message box to prove we were here //VsShellUtilities.ShowMessageBox( // this.ServiceProvider, // message, // title, // OLEMSGICON.OLEMSGICON_INFO, // OLEMSGBUTTON.OLEMSGBUTTON_OK, // OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); FASTBuildPackage fbPackage = (FASTBuildPackage)this.package; if (null == fbPackage.m_dte.Solution) { return; } Solution sln = fbPackage.m_dte.Solution; SolutionBuild sb = sln.SolutionBuild; SolutionConfiguration2 sc = sb.ActiveConfiguration as SolutionConfiguration2; string startupProject = ""; foreach (String item in (Array)sb.StartupProjects) { startupProject += item; } var proj = sln.Item(startupProject).Object as VCProject; fbPackage.m_dte.ToolWindows.SolutionExplorer.GetItem("ConsoleApplication1\\ConsoleApplication1").Select(vsUISelectionType.vsUISelectionTypeSelect); fbPackage.m_dte.ExecuteCommand("ClassViewContextMenus.ClassViewProject.Debug.Startnewinstance"); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { FASTBuildPackage fbPackage = (FASTBuildPackage)this.package; if (null == fbPackage.m_dte.Solution) { return; } MenuCommand eventSender = sender as MenuCommand; fbPackage.m_outputPane.Activate(); fbPackage.m_outputPane.Clear(); if (eventSender == null) { fbPackage.m_outputPane.OutputString("VSIX failed to cast sender to OleMenuCommand.\r"); return; } if (fbPackage.m_dte.Debugger.CurrentMode != dbgDebugMode.dbgDesignMode) { fbPackage.m_outputPane.OutputString("Build not launched due to active debugger.\r"); return; } if (!IsFBuildFindable(fbPackage.OptionFBPath)) { fbPackage.m_outputPane.OutputString(string.Format("Could not find fbuild at the provided path: {0}, please verify in the msfastbuild options.\r", fbPackage.OptionFBPath)); return; } fbPackage.m_dte.ExecuteCommand("File.SaveAll"); string fbCommandLine = ""; string fbWorkingDirectory = ""; Solution sln = fbPackage.m_dte.Solution; SolutionBuild sb = sln.SolutionBuild; SolutionConfiguration2 sc = sb.ActiveConfiguration as SolutionConfiguration2; VCProject proj = null; if (eventSender.CommandID.ID != SlnCommandId && eventSender.CommandID.ID != SlnContextCommandId) { if (fbPackage.m_dte.SelectedItems.Count > 0) { Project envProj = (fbPackage.m_dte.SelectedItems.Item(1).Project as EnvDTE.Project); if (envProj != null) { proj = envProj.Object as VCProject; } } if (proj == null) { string startupProject = ""; foreach (String item in (Array)sb.StartupProjects) { startupProject += item; } proj = sln.Item(startupProject).Object as VCProject; } if (proj == null) { fbPackage.m_outputPane.OutputString("No valid vcproj selected for building or set as the startup project.\r"); return; } fbPackage.m_outputPane.OutputString("Building " + Path.GetFileName(proj.ProjectFile) + " " + sc.Name + " " + sc.PlatformName + "\r"); fbCommandLine = string.Format("-p \"{0}\" -c {1} -f {2} -s \"{3}\" -a\"{4}\" -e \"{5}\"", Path.GetFileName(proj.ProjectFile), sc.Name, sc.PlatformName, sln.FileName, fbPackage.OptionFBArgs, fbPackage.OptionFBPath); fbWorkingDirectory = Path.GetDirectoryName(proj.ProjectFile); } else { fbCommandLine = string.Format("-s \"{0}\" -c {1} -f {2} -a\"{3}\" -e \"{4}\"", sln.FileName, sc.Name, sc.PlatformName, fbPackage.OptionFBArgs, fbPackage.OptionFBPath); fbWorkingDirectory = Path.GetDirectoryName(sln.FileName); } if (fbPackage.OptionBrokerage.Length > 0) { fbCommandLine += " -b " + fbPackage.OptionBrokerage; } if (fbPackage.OptionFBUnity) { fbCommandLine += " -u true"; } string msfastbuildPath = Assembly.GetAssembly(typeof(msfastbuild.msfastbuild)).Location; try { fbPackage.m_outputPane.OutputString("Launching msfastbuild with command line: " + fbCommandLine + "\r"); System.Diagnostics.Process FBProcess = new System.Diagnostics.Process(); FBProcess.StartInfo.FileName = msfastbuildPath; FBProcess.StartInfo.Arguments = fbCommandLine; FBProcess.StartInfo.WorkingDirectory = fbWorkingDirectory; FBProcess.StartInfo.RedirectStandardOutput = true; FBProcess.StartInfo.UseShellExecute = false; FBProcess.StartInfo.CreateNoWindow = true; var SystemEncoding = System.Globalization.CultureInfo.GetCultureInfo(GetSystemDefaultLCID()).TextInfo.OEMCodePage; FBProcess.StartInfo.StandardOutputEncoding = System.Text.Encoding.GetEncoding(SystemEncoding); System.Diagnostics.DataReceivedEventHandler OutputEventHandler = (Sender, Args) => { if (Args.Data != null) { fbPackage.m_outputPane.OutputString(Args.Data + "\r"); } }; FBProcess.OutputDataReceived += OutputEventHandler; FBProcess.Start(); FBProcess.BeginOutputReadLine(); //FBProcess.WaitForExit(); } catch (Exception ex) { fbPackage.m_outputPane.OutputString("VSIX exception launching msfastbuild. Could be a broken VSIX? Exception: " + ex.Message + "\r"); } }