Is it possible to get the DTE2 com object when starting devenv.exe with parameters...?  
Author Message
paulpayne





PostPosted: Visual Studio Extensibility, Is it possible to get the DTE2 com object when starting devenv.exe with parameters...? Top

I am currently writing some Visual Studio automation and would like to use the experimental hive so that when one of our users fires off Visual Studio from within our code any changes we make through code to windows toolbars etc are not persisted in their main version of Visual Studio. I have experimented with windows configurations, restoring settings on close etc, but this is still to risky for my liking (if the program crashes Visual Studio will be pretty messed up next time it is loaded outside of our code!!). This works perfectly from the command line using the rootsuffx argument but my problem lies in the fact that I need to start devenv.exe from code and get hold of the DTE2 com object. At present we do this by getting the CLSID or the ProgID and using system.activator like so...

System.Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE.8.0");
Object obj = System.Activator.CreateInstance(type, true);
this.m_visualStudio = (EnvDTE80.DTE2)obj;

How can I do this with command line arguments Is there a way of getting a com object from a running process i.e. I could create the process, get the processId then generate the com object for that process somehow or is that not how com objects work

I've already tried adding the switch to the LocalServer32 entry for VisualStudio.DTE.8.0 to see if that worked but then system.activator returns a directory not found exception (which I am sure is not down to the syntax I'm using in the registry entry...


"C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.exe /RootSuffix Exp"

Any help would be much appreciated - if this works we can then generate our own seperate hive and use that for our VS interop which would be the ideal...

Regards

Paul




Visual Studio42  
 
 
amadeus1eu





PostPosted: Visual Studio Extensibility, Is it possible to get the DTE2 com object when starting devenv.exe with parameters...? Top

Hallo,

Are you developing an application that allows users to expand your environment creating scripts, or in any way need a development environment for an application of your own How can you be sure that all your users will have VS 2005 installed And even if they do, it's most unlikely that they also have an experimental hive created (which btw requires a licence).

It seems to me that what you are trying to do, relies on Microsoft Visual Studio 2005 Tools for Applications (VSTA). Using VSTA allows you to customize the VS 2005 IDE, any way you want to accomodate your needs, and also distribute it with your application. There is a price for this of course and this version of the IDE will ony contain the products (language services and packages), you add. Not the regular language services and packages that come with VS 2005.

You can learn all about it here (you will also learn there about the simplified and transparent ISV pricing model). Then go here (login required) and download the Visual Studio 3.0 SDK (August 2006 CTP). This is not the latest SDK but it's the latest that contains VSTA and as KD Hallman says...

Happy Customization!



 
 
paulpayne





PostPosted: Visual Studio Extensibility, Is it possible to get the DTE2 com object when starting devenv.exe with parameters...? Top

Hello,

Thanks for your reply, we have looked at VSTA but as all our clients will have VS2005 there is no point in using it - in fact the whole interface surrounding it is way to restrictive for what we are doing. We have a full API into our application which clients can program against in .net code. All we require is a code editor with intellisense - we do all the compiling by extracting the source code and using the Code DOM compiler to compile it and store it in our Db.

The reason we are in this situation is that we used to use VSA for our script editing, but MS deprocated it. Now we have to find a suitable replacement and VSTA as far removed from the simplicity of VSA. Unless we can hook into Visual Studio without fear of messing up settings (we end up hiding windows and toolbars so users can't do anything other than edit a page of code) we will probably have to take a more internal approach to our integration and use VSIP to bring our entire development experience into VS2005.


 
 
Craig Skibo - MSFT





PostPosted: Visual Studio Extensibility, Is it possible to get the DTE2 com object when starting devenv.exe with parameters...? Top

What you want to do instead of creating a new instance using the COM activator is to spawn a new process using System.Diagnostics.Process.Start. This will return back to you a process ID, which you can then go into the running object table and look for the moniker "VisualSutdio.DTE.8.0!1234", where 1234 is the process ID returned from the call to System.Diagnostics.Process.Start.

Craig



 
 
Will VV





PostPosted: Visual Studio Extensibility, Is it possible to get the DTE2 com object when starting devenv.exe with parameters...? Top

Hi Craig

I'm having a similar problem, currently I'm starting a new instance of VS with System.Diagnostics.Process.Start()

The IDE executes just fine, the problem is when I try to get the DTE object for that instance, I'm doing this:

DTE2 dte = (EnvDTE80.DTE2)Marshal.GetActiveObject("VisualStudio.DTE.8.0!" + processId);

The processId is from the process executing VS.

It throws this error in that line:

Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))

Am I doing something wrong

Thanks for your help


 
 
Leonard Jiang





PostPosted: Visual Studio Extensibility, Is it possible to get the DTE2 com object when starting devenv.exe with parameters...? Top

Hi Will VV,

Yesterday, I also got the problem as yours when I want to attach to one specified DTE instance in VS 2005(Version:8.0.50727) . Fortunately, I solve it now. So, here attach what I found, and hope it could help you.

1. The actual item moniker should be like as "!VisualStudio.DTE.8.0:1234" but not "VisualStudio.DTE.8.0!1234" stated in VS 2005 MSDN. I just found this difference after checking running object table.

2. After get accurate item moniker, we could get specified DTE instance by lookuping running object able. Below are code fragement for your information, which I used in my program:

[DllImport("ole32.dll")]

static extern int GetRunningObjectTable(uint reserved, out IRunningObjectTable pprot);

[DllImport("ole32.dll")]

static extern int CreateBindCtx(uint reserved, out IBindCtx pctx);

private static DTE2 SeekDTE2InstanceFromROT(String moniker)

{

//

IRunningObjectTable prot = null;

IEnumMoniker pmonkenum = null;

IntPtr pfeteched = IntPtr.Zero;

DTE2 ret = null;

try

{

//get rot

if ((GetRunningObjectTable(0, out prot) != 0) || (prot == null)) return ret;

prot.EnumRunning(out pmonkenum);

pmonkenum.Reset();

IMoniker[] monikers = new IMoniker[1];

while (pmonkenum.Next(1, monikers, pfeteched) == 0)

{

String insname;

IBindCtx pctx;

CreateBindCtx(0, out pctx);

monikers[0].GetDisplayName(pctx, null, out insname);

Marshal.ReleaseComObject(pctx);

if (string.Compare(insname, moniker) == 0) //lookup by item moniker

{

Object obj;

prot.GetObject(monikers[0], out obj);

ret = (DTE2)obj;

}

}

}

finally

{

if (prot != null) Marshal.ReleaseComObject(prot);

if (pmonkenum != null) Marshal.ReleaseComObject(pmonkenum);

}

return ret;

}

Then you can use like as : SeekDTE2InstanceFromROT("!VisualStudio.DTE.8.0:1234");

Hope it could help you!

Leonard


 
 
Will VV





PostPosted: Visual Studio Extensibility, Is it possible to get the DTE2 com object when starting devenv.exe with parameters...? Top

Thanks Leonard

Actually yesterday I also found the same solution... LOL

This works perfect!