Start New Instance of specific project

184 Views Asked by At

I am trying to start a new instance of a project in my solution. I know I can change the StartupProjects and then start the debugger, but in my case this does not work, because the debugger might already be running and I don't want to change the startup project anyway.

var dte2 = Package.GetGlobalService(typeof(DTE)) as DTE2;
foreach (Project project in dte2.Solution.Projects)
{
    if(project.UniqueName == "blahblah";
    {
         // Whatever right-click on a project
         // Debug -> Start New Instance 
         // does.
    }
}

I don't want to use dte2.Debugger.Go() because the startup project is not the one I want to start.

How I I manually start debugging a new instance of my project?

Update: My current solution (workaround) looks like this:

dte2.Solution.SolutionBuild.BuildProject(
    dte2.Solution.SolutionBuild.ActiveConfiguration.Name,
    "Test",
    true);

Process process = Process.Start(pPath);
Processes processes = dte2.Debugger.LocalProcesses;
foreach (EnvDTE.Process proc in processes)
{
    if (proc.ProcessID == process.Id)
    {
        Debug.Write("Attaching to: " + proc.Name + " - " + proc.ProcessID);
        proc.Attach();
    }
}

It basically builds the project, starts the exe in a new process and then attaches to the process. The only problem I have now is that when I start the build and there is already a debugging session in process, Visual Studio will ask me, whether I want to stop debugging (in order to build). But when I select "Start new instance" in the context menu, it doesn't!

0

There are 0 best solutions below