Katy -> Visual C++ Stuff -> Automating Developer Studio


Pet Peeves with Developer Studio Automation

Lately, I've been working on adding some automation to Developer Studio, and keep running up against some shortcomings in the published interfaces. Here's my current list of things I'd like to be able to do with DevStudio automation, either with macros or by writing an add-in.

  1. Setting ActiveProject fails Solved!
  2. Export a specific makefile Partial solution
  3. Update dependencies for a project Partial solution
  4. How do you tell if a project is up to date? Workaround
  5. Can automation load and unload projects?
  6. What files are in a project?
  7. Was Build|Clean or Build|Build chosen?
  8. Where are the .DSW and .DSP files? Solved!

     


Setting ActiveProject fails

BUG: All attempts to set the active project, e.g.

    Sub Test
      Application.ActiveProject = "MyProject"
    End Sub

return an error, "attempt to write read-only property".

Solution 10/23/1997
This is just the lack of a good example in the online help. In order to set the active project, you must use the set keyword, and set the project to a specific object, not to a string. For example:

Sub ChangeActiveProject(ProjectName)
'DESCRIPTION: Change the active project to the named project.
'             Note that the named project must be loaded into the
'             current workspace, since unloaded projects aren't 
'             part of the list managed by the Projects object
    i = 1
    Do While i < = Application.Projects.Count 
      if Application.Projects.Item(i).Name="ProjectName" Then 
        Set Application.ActiveProject = Application.Projects.Item(i)
      end if
      i = i + 1  ' go on to the next project.
    Loop
End Sub

Export a specific makefile

Is there a way of exporting .dsp files to .mak files from the command line?

Use a macro:

Sub ExportMakefile()
  ExecuteCommand "BuildProjectExport"
  Quit ' Quits DevStudio
End Sub

Run from the command line with

msdev MyProj.dsw -ex ExportMakefile -nologo

The macro will pop up a dialog box if there are multiple projects in the workspace. (the -nologo just suppresses the splash screen)

Unfortunately, there seems to be no way to bypass the dialog box for workspaces with multiple projects. It would be nice to find a way to bypass the dialog, so this macro could be used to do night builds.

Update dependencies for a project

Update dependencies for a specific project. Again,

    ExecuteCommand "BuildUpdateAllDependencies"

works fine with a single-project workspace, but displays a dialog box for multiple-project workspaces.

How do you tell if a project is up to date?

The Project or BuildProject object should have a boolean IsUpToDate property, which returns a status similar to NMAKE /Q

Can automation load and unload projects?

I want to be able to activate the command found only on the context menu of the FileView tree: "Load Project", "Unload Project"

What files are in a project?

The Project object should allow you to enumerate the folders and files in the project. This would allow me to run a tool on each file (e.g. a spelling checker, function point counter, lint program, whatever). Each file would also have a Configuration object too, of course.

Was Build|Clean or Build|Build chosen?

From within an BeforeBuildStart handler, there should be some way to tell whether a Build | Clean or Build | Build caused the event, or there should be two different events.

Where are the .DSW and .DSP files?

The Project (BuildProject) object should have a Path property. There is currently no way to determine the root path for a project, although the "current directory" seems to be a good guess, at least in a BeforeBuildStart handler.

Solution 10/23/1997 You can always determine the path to the current workspace by looking in the registry, since opening a workspace always puts it as #1 in the Recent Workspaces list. So you can look it up in

HKEY_CURRENT_USER\SOFTWARE\Microsoft\DevStudio\5.0\Recent File List\Project1

Finding the path(s) to the projects contained in the workspace is still a problem, though.

An undocumented property (FullName) of the IGenericProject interface allows you to determine the full path to a project. For example, the following macro prints the full paths to each project in the Macro tab.

Sub DisplayProjectPaths()
'DESCRIPTION: Print the paths of all the projects in the workspace
  For Each aProject in Application.Projects
    PrintToOutputWindow aProject.FullName
  Next
End Sub

 

 


No solicitation beyond this point.
Don't even think of adding me to your mailing list. Put up a web page I'm interested in, and let me ask you for information.
Comments? Questions? Send mail to Katy

This page was last modified on 1998/08/23