public static StartParameters FromProperties(Properties properties) { var result = new StartParameters { StartAction = (StartAction)properties.Item("StartAction").Value, StartWorkingDirectory = properties.Item("StartWorkingDirectory").Value.ToString(), StartProgram = properties.Item("StartProgram").Value.ToString(), StartArguments = properties.Item("StartArguments").Value.ToString() }; return(result); }
private static string GetExeName(StartParameters startParameters, Project startupProject) { if (startParameters.StartAction == StartAction.Program) { return(Path.GetFileName(startParameters.StartProgram)); } if (startParameters.StartAction == StartAction.StartupProject) { return(string.Format("{0}.exe", Path.GetFileNameWithoutExtension(startupProject.FileName))); } return(null); }
private int StartProcess() { var solutionInfo = new SolutionInfo(GetDte()); var solutionDir = solutionInfo.TargetWorkingDirectory; if (solutionDir != null) { var startupProjectName = ((Array)solutionInfo.Solution.SolutionBuild.StartupProjects).Cast <string>().First(); var startupProject = solutionInfo.Solution.Projects.Item(startupProjectName); var configurationManager = startupProject.ConfigurationManager; var activeConfiguration = configurationManager.ActiveConfiguration; var startParameters = StartParameters.FromProperties(activeConfiguration.Properties); var exeName = Path.Combine(solutionDir, GetExeName(startParameters, startupProject)); try { var processStartInfo = new ProcessStartInfo(exeName) { WorkingDirectory = solutionDir, Arguments = startParameters.StartArguments, UseShellExecute = false }; debuggedProcess = new Process { StartInfo = processStartInfo }; debuggedProcess.Start(); var processId = debuggedProcess.Id; return(processId); } catch (Exception ex) { MessageBox.Show( string.Format( "Failed to start '{0}'.{1}" + "Check Debug\\Properties\\Debug\\Startup action.{1}{1}" + "{2}", exeName, Environment.NewLine, ex), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } return(-1); }