Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / February 2005

Tip: Looking for answers? Try searching our database.

Access to DTE (solution and project) object model on command line

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RafaelC - 11 Feb 2005 06:31 GMT
Hello,

I have a VS project that has the Configuration type set to Makefile and
basically calls a ToolApp (EXE) I wrote that goes through the project's
sources and calls the compiler/linker, etc.  It all works well when I have
the solution/project opened in VS .NET 2003 IDE, but I would like to make
builds at night, so I call from the command line:

devenv.exe "C:\myproject.sln" /build "Debug" /project "myproject"

My ToolApp gets called correctly, but looks like I'm not able to get a
pointer to DTE anymore (needed to get the solution, project and collection of
files in the project), is there any way to get this when devenv.exe is called
from the command line as above?  This is what I've tried:

hr = CLSIDFromProgID(OLESTR("VisualStudio.DTE"), &clsid);
if (SUCCEEDED(hr))
{
   hr = GetActiveObject(clsid, NULL, &pUnknown);
  // hr is -2147221021 when ran on the command line
   if (SUCCEEDED(hr))
   {       //I don't get in here if ran from the command line
         pUnknown->QueryInterface(__uuidof(EnvDTE::_DTE), (LPVOID*)&gDTE);
...

Please don't tell me I have to parse the .vcproj to get the settings, and
project files...   :-)

thanks in advance
Carlos J. Quintero [.NET MVP] - 11 Feb 2005 12:25 GMT
There are some things that I don´t fully understand your scenario, such as
launching the IDE from the command line for a build and then trying to
attach an My ToolApp application to it while the build is being performed
but to my knowledge there are 2 ways to do what you want:

- You convert My ToolApp into an add-in, which is loaded with VS.NET when
the IDE is loaded from the command line for builds. In this case the
ConnectionMode parameter of the OnConnection method receives the value
Extensibility.ext_ConnectMode.ext_cm_CommandLine. Your add-in traps
pre-build and post build events or similar to perform its actions.

- My ToolApp is not an add-in but a standalone tool which creates an
instance of VS.NET and uses automation to control the IDE. You do this from
your tool with

objDTE = CreateObject("VisualStudio.DTE")    (or similar statement for your
language)

Once you have the root objDTE, you can load a solution
(objDTE.Solution.Open), navigate its projects (objDTE.Solution.Projects) and
compile it (objDTE.Solution.SolutionBuild.Build), etc. Notice that in this
approach you don't use devenv.exe /build.

Signature

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com

> Hello,
It all works well when I have
> the solution/project opened in VS .NET 2003 IDE, but I would like to make
> builds at night, so I call from the command line:
[quoted text clipped - 22 lines]
>
> thanks in advance
RafaelC - 11 Feb 2005 17:49 GMT
Hola Carlos,

Sorry for not describing the issue in a clear form.  Ok, here's the scenario:

A .vcproj is created through wizards, once the project is created, I set the
"Configuration Type" to "Makefile" in the "General" page and in the "Build
Command Line" field of the "NMake" page settings, I put in my Win32 ToolApp
(EXE) I wrote.  When "build" is selected, my ToolApp gets called and gets the
DTE and goes through the project sources and calls the compiler/linker, etc.  
So ToolApp is not an add-in but rather a tool that uses the automation
interfaces.

All of the above works ok if I double click on the IDE and open the
solution/project and when I select build from the VS .NET menu, it calls my
ToolApp, etc.
Now, I want to build the project through the command line without having to
double click on the IDE open the project, etc, or without seeing an instance
of the IDE come up.  I'd like to do:

devenv.exe "C:\myproject.sln" /build "Debug" /project "myproject"

and just build on the command line.  With the command line above, my ToolApp
gets called correctly, but inside ToolApp I'm not able to get the DTE with
GetActiveObject().

Do you know if by using:
CreateObject("VisualStudio.DTE")
objDTE.Solution.Open
objDTE.Solution.Projects

would create a (visual) instance of the IDE?

I hope I explained it better this time, if not, please let me know.  Any
other suggestions are welcomed.

Gracias

> There are some things that I don´t fully understand your scenario, such as
> launching the IDE from the command line for a build and then trying to
[quoted text clipped - 47 lines]
> >
> > thanks in advance
RafaelC - 11 Feb 2005 23:17 GMT
Ok, doing a CoCreateInstance does what I need.

nevermind...

thanks

>  Hola Carlos,
>
[quoted text clipped - 84 lines]
> > >
> > > thanks in advance
RafaelC - 11 Feb 2005 20:01 GMT
By the way, I'm using C++ and not VB, what is a similar VB CreateObject()
call in C++?  CoCreateInstance()?
If so, I don't think it will work as CoCreateInstance() will make the IDE
come up....

> There are some things that I don´t fully understand your scenario, such as
> launching the IDE from the command line for a build and then trying to
[quoted text clipped - 47 lines]
> >
> > thanks in advance

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.