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?
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.
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?
精彩评论