Visual Studio 2010 Automation and Environment Variables

I am opening VS2010 solutions using C # and VS2010. I open such solutions as follows:

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

The problem I am facing is that when I instantiate the VisualStudio.DTE.10.0 object, it starts the devenv.exe process from winlogon.exe , which sees a completely different environment than my application. Some environment variables are important for solving some of the paths defined in projects.

Is there a way to affect the environment variables of the devenv.exe process? Is it possible to somehow embed the environment / properties using the VS2010 automation interfaces?

+6
source share
2 answers

Is it possible to run devenv yourself inside your environment. Then grab a running instance of Visual Studio through a table of running objects (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 have problems if you have multiple instances of VS, but it is also easy. You can get a specific VS instance where you only need to know the process ID of your own VS instance.

Visual Studio also registers the ProgID as an element in the ROT. The progID consists of the name and process identifier of the DTE process. So, for example, the ROT object record can be "! VisualStudio.DTE.10.0: 1234", where 1234 is the process identifier.

+2
source

I'm not quite sure that this is what you are looking for, but Windows environment variables can be changed (taking into account Windows 7): Control Panel → System and Security → System → Advanced System Settings → Environment Variables (button).

On this screen, you can set user variables as well as system variables. Perhaps the settings that you want to find in your application are stored under the user, and not in the system, and then open the application under another user so that these variables are not available?

Create the variables you need as system variables solve your problem?

0
source

Source: https://habr.com/ru/post/897376/


All Articles