Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2010 automation and environment variables

I am opening VS2010 solutions using C# and VS2010 automation. I open the solutions like this:

Type type = Type.GetTypeFromProgID("VisualStudio.DTE.10.0", true);
Object comObject = Activator.CreateInstance(type);
...
sol.Open(solution_full_path);

The problem I am having is that when I create the instance of the VisualStudio.DTE.10.0 object, it starts the devenv.exe process from winlogon.exe which sees completely different environment than my application. Some of the environment variables are important for resolving some paths set in projects.

Is there any how I can influence the environment variables of the devenv.exe process? Is there any way how I could inject environment/properties using the VS2010 automation interfaces?

like image 508
wilx Avatar asked Sep 15 '11 09:09

wilx


1 Answers

Is it possible to start devenv by yourself inside your environment. Then get your hands on the running Visual Studio Instance via the running object table (ROT).

// Get an instance of the currently running Visual Studio IDE.
EnvDTE80.DTE2 dte2;
dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.
GetActiveObject("VisualStudio.DTE.10.0");

You will get problems if you have more than one running VS instance but this also an easy one. You can get your hands on a specific VS instance where you only need to know the process id of your self started VS instance.

Visual Studio also registers a ProgID as an item moniker in the ROT. The ProgID is comprised of the name and process ID of the DTE process. So, for example, the object's ROT entry might be "!VisualStudio.DTE.10.0:1234," where 1234 is the process ID.

like image 192
Alois Kraus Avatar answered Sep 21 '22 19:09

Alois Kraus