2

My use case is that with one piece of code run as .exe., say A project, I need to execute another C# executable, say B project, which is being developed simultaneously. The B project execution is handled with the Process .NET type.

This is how the B project is executed

public override string Run(string executablePath)
{
    Process environmentProcess = new Process();

    string inputPath = GetInputPath();
    string inputFormat = GetInputFormat();
    string outputPath = GetOutputPath();

    GenerateOptions(inputPath, inputFormat);

    string args = string.Format("-i \"{0}\" -f {1} -o \"{2}\"", inputPath, inputFormat, outputPath);

    ProcessStartInfo startInfo = new ProcessStartInfo
    {
        FileName = executablePath,
        Arguments = args
    };

    environmentProcess.StartInfo = startInfo;
    environmentProcess.Start();
    environmentProcess.WaitForExit();

    return GetOutput(outputPath);
}

To run the solution, I simply hit F5 and that runs A with the debugger attached and the A process in turn executes B

What I want to achieve is to automate the process of attaching the debugger to the B process. I know of System.Diagnostics.Debugger.Launch();, yet this creates a whole new VS instance to attach debugger to. I want it almost exactly this way, except that I want to be able make B attach to the existing instance of Visual Studio and its debugger.

Is it even possible?

patryk
  • 651
  • 12
  • 30
  • Did you tried multiple startup projects? Right click solution window->Select Properties->Select Startup project-> Check Multiple startup projects and change the action to start for each project type. – Bikal Bhattarai Apr 23 '15 at 19:59
  • 1
    I should have given an explicit code snippet for how I execute the `B` project. See my upcoming update – patryk Apr 23 '15 at 20:01
  • 1
    [this link](https://msdn.microsoft.com/en-us/library/jj919165.aspx) looks like what you are looking for... – Old Fox Apr 23 '15 at 20:02
  • Thank you for the resource. Reviewing the contents tells me it's in fact about debugging multiple processes simultaneously, however this covers how to run one or more processes by VS explicitly. My case is different - the other `B` executable is meant to be run by the `A` project at some point. I fail to see any details on this case :( – patryk Apr 23 '15 at 20:53
  • 1
    WinDbg allows you to debug child processes. – Brian Rasmussen Apr 23 '15 at 21:09
  • http://entrian.com/attach/ adds exactly this feature to Visual Studio. (Disclosure: it's a commercial product, and I wrote it.) – RichieHindle Apr 24 '15 at 11:56
  • See https://stackoverflow.com/questions/1626458/how-to-attach-a-debugger-dynamically-to-a-specific-process – Mohammad Mar 12 '19 at 12:26

0 Answers0