private void ProjectContextMenuItemCallback(object sender, EventArgs e) { var dte = this.dte.DTE; OutputWindow outputWindow = null; try { outputWindow = new OutputWindow(dte); OleMenuCommand menuCommand = sender as OleMenuCommand; if (menuCommand != null && dte != null) { Array selectedProjects = (Array)dte.ActiveSolutionProjects; //only support 1 selected project if (selectedProjects.Length == 1) { EnvDTE.Project project = (EnvDTE.Project)selectedProjects.GetValue(0); var vcproj = project.Object as VCProject; if (vcproj != null) { IVCCollection configs = (IVCCollection)vcproj.Configurations; VCConfiguration cfg = (VCConfiguration)vcproj.ActiveConfiguration; VCDebugSettings debug = (VCDebugSettings)cfg.DebugSettings; string command = null; string arguments = null; string workingDirectory = null; if (debug != null) { command = cfg.Evaluate(debug.Command); workingDirectory = cfg.Evaluate(debug.WorkingDirectory); arguments = cfg.Evaluate(debug.CommandArguments); } VCPlatform currentPlatform = (VCPlatform)cfg.Platform; string platform = currentPlatform == null ? null : currentPlatform.Name; if (platform != null) { platform = platform.ToLower(); if (platform.Contains("x64")) { platform = "x64"; } else if (platform.Contains("x86") || platform.Contains("win32")) { platform = "x86"; } else { throw new NotSupportedException("Platform is not supported."); } } else { cfg = (VCConfiguration)configs.Item("Debug|x64"); platform = "x64"; if (cfg == null) { throw new NotSupportedException("Cannot find x64 platform for project."); } } if (command == null || String.IsNullOrEmpty(command)) { command = cfg.PrimaryOutput; } if (command != null) { var solutionFolder = System.IO.Path.GetDirectoryName(dte.Solution.FileName); CoverageExecution executor = new CoverageExecution(dte, outputWindow); executor.Start( solutionFolder, platform, System.IO.Path.GetDirectoryName(command), System.IO.Path.GetFileName(command), workingDirectory, arguments); } } } } } catch (NotSupportedException ex) { if (outputWindow != null) { outputWindow.WriteLine("Error running coverage: {0}", ex.Message); } } catch (Exception ex) { if (outputWindow != null) { outputWindow.WriteLine("Unexpected code coverage failure; error: {0}", ex.ToString()); } } Settings.Instance.TriggerRedraw(); }