Visual Studio 2010 automation and environment variables

狂风中的少年 提交于 2019-12-21 13:11:07

问题


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?


回答1:


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.




回答2:


Not entirely sure if this is what you are looking for, but windows environment variables can be changed from (assuming Windows 7): Control Panel -> System and Security -> System -> Advanced System Settings -> Environment Variables (button).

In this screen, you can set user variables as well as system variables. Perhaps the settings you want your app to find are stored under the user, rather than the system, and then opening the app under a different user causes those variables to not be available?

Would creating the variables you need as system variables solve your problem?



来源:https://stackoverflow.com/questions/7428733/visual-studio-2010-automation-and-environment-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!