I have a C# Code Analysis Application that opens C# using ProcessStartInfo
And Process Start. It almost works.
I want to use two instance of VS to perform the analysis: one to Debug the Analysis App, and another to have the File that is specified in its appropriate Solution.
Currently the C# File always opens in the Analysis App Debug Session, not the Analyzed App Solution. How can I specify which Instance to use upon Process.Start(ProcessStartInfo)?
private void OpenFileExecute(string file)
{
ProcessStartInfo psi = new ProcessStartInfo(file);
psi.UseShellExecute = true;
Process.Start(psi);
}
With the standard open method you'll not be able to control which running instance will be used. Under the hood it uses DDE and it is undetermined which instance will handle DDE requests.
The same goes for when you use
Activator.GetObject
.Luckily, in ole32.dll we can call GetRunningObjectTable and from there enumerate over all instances to find all registered OLE Servers, for each instance and that includes all Visual Studio processes.
Once we found one you can obtain an instance to its OLE Automation interface, EnvDTE and use that to inspect in-depth if this is the right instance to interact with, and if yes, execute any command we're interested in, for example loading a file.
Background reading: How to use Marshal.getActiveObject() to get 2 instance of of a running process that has two processes open