Share via


Macro Project Object Model

Visual Studio includes tools for writing and recording macros. (For an overview, see Automating Repetitive Actions by Using Macros.) Visual Studio also includes a programmable object model that exposes macro projects. This model contains both general extensibility objects for language-neutral project items and macro-specific objects. The macro-specific objects, found in the VSLangProj, VSLangProj2 and VSLangProj80 namespaces, are used just as in Visual Basic and Visual C# projects. This topic discusses:

For more information on VSLangProj, VSLangProj2 and VSLangProj80 objects, see Introduction to Project Extensibility. For more information on general extensibility, see Extending the Visual Studio Environment.

Accessing the Extensibility Objects of a Macro Project

Macro projects are accessed through the MacrosIDE property of the DTE2 extensibility object. The MacrosIDE property returns an object of type DTE2, so that you have access to the Macros integrated development environment (IDE), including solutions, projects, tool windows, documents, and events. The following macro lists all the modules in a macro project.

' Macro editor
Public Sub FindMacros()
   Dim macroproject As Project
   ' Retrieve the first project in the Macros IDE.
   macroproject = DTE.MacrosIDE.Solution.Projects.Item(1)
   ' Display the project's name.
   MsgBox(macroproject.Name)
   ' Display each project item (module).
   Dim projitem As ProjectItem
   For Each projitem In macroproject.ProjectItems
      MsgBox(projitem.Name)
   Next
End Sub 

Macro Projects and the VSLangProj Objects

In the general extensibility model, a project is represented by the generic Project object. The Project object has an Object property. In a macro project, the Object property returns an object of type VSProject. Because the type of the Object property is object, you must cast the reference to type VSProject. You can use the PrjKind or PrjKind2 enumeration to check the project type before making the case. The cast would look like the following if done in a macro:

' Macro editor
Public Sub CastToVSProject()
   ' Retrieve the general extensibility object.
   Dim macroproject As Project
   macroproject = DTE.MacrosIDE.Solution.Projects.Item(1)

   ' Cast for the macro specific information.
   Dim vsproj As VSLangProj.VSProject

   ' Can test type of project before cast.
   If (macroproject.Kind = VSLangProj.PrjKind.prjKindVSAProject) Then
      vsproj = CType(macroproject.Object, VSLangProj.VSProject)
   End If
   MsgBox(vsproj.Project.Name)
End Sub

The VSProject2 object is the container for several other objects in the VSLangProj, VSLangProj2 and VSLangProj80 namespaces, including References, Reference, Imports, and BuildManager objects.

In the general extensibility model, a project item is represented by the generic ProjectItem object. The ProjectItem object has an Object property. In a macro project, the Object property returns an object of type VSProjectItem. Since the type of the Object property is Object, you must cast the reference to type VSProjectItem. The cast would look like the following if done in a macro:

' Macro editor
Public Sub CastToVSProjectItem()
   Dim projitem As ProjectItem
   Dim vsitem As VSLangProj.VSProjectItem
   For Each projitem In _
      DTE.MacrosIDE.Solution.Projects.Item(1).ProjectItems
      vsitem = CType(projitem.Object, VSLangProj.VSProjectItem)
      MsgBox(vsitem.ProjectItem.Name)
   Next
End Sub

Macro-specific Elements of the VSLangProj Objects

The objects in the VSLangProj, VSLangProj2 and VSLangProj80 namespaces are used for Visual Basic, Visual C# and macro projects. There are some enumeration values that are particular to macro projects. The PrjKind enumeration has a value for macro projects, prjKindVSAProject. The PrjBrowseObjectCATID enumeration has the following values for extending the items in the Properties window:

prjCATIDVSAFolderBrowseObject

prjCATIDVSAFileBrowseObject

prjCATIDVSAConfig

prjCATIDVSAReferenceBrowseObject

Macro-specific Behavior of the VSLangProj Objects

The behavior of the VSLangProj, VSLangProj2 and VSLangProj80 objects varies slightly among Visual Basic, Visual C# and macro projects. This is so that the object accurately represents the project type. Many properties and methods of the objects are not supported for macro projects, as listed below.

VSProject   This object represents the macro-specific details of a project.

  • BuildManager This property is not supported, and accessing this property throws an exception.

  • CopyProject This method is not supported, and calling this method throws an exception.

  • WorkOffline This property always returns False. Trying to set this property does not throw an exception, but the property cannot be set to True.

VSProjectItem   This object represents the macro-specific details of a project item.

  • RunCustomTool This method is not supported, and calling this method throws an exception.

ProjectProperties3   These properties describe Visual Basic, Visual C# and macro projects. The following properties are not supported:

ActiveFileSharePath

FullPath

ApplicationIcon

LinkRepair

AssemblyName

OfflineURL

AssemblyKeyContainerName

OutputFileName

AssemblyOriginatorKeyFile

OutputType

AssemblyOriginatorKeyMode

URL

DefaultClientScript

WebAccessMethod

DefaultHTMLPageLayout

WebServer

DefaultTargetSchema

WebServerVersion

ActiveFileSharePath

 

FileProperties2   These properties describe Visual Basic, Visual C# and macro project items. The following file properties are not supported, and accessing them will throw an error:

Author

FullPath

BuildAction

IsDependentFile

IsCustomToolOutput

IsDesignTimeBuildInput

CustomToolNamespace

IsLink

CustomToolOutput

HTMLTitle

DateCreated

LocalPath

DateModified

ModifiedBy

Extension

SubType

FileName

URL

The following FolderProperties2 are not supported, and accessing them will throw an error.

FullPath

URL

LocalPath

 

ProjectConfigurationProperties3   These properties describe Visual Basic, Visual C# and macro deployment configurations. The following file properties are not supported, and accessing them will throw an error:

AllowUnsafeBlocks

IntermediatePath

BaseAddress

OutputPath

CheckForOverflowUnderflow

StartAction

DocumentationFile

StartArguments

EnableASPXDebugging

StartProgram

EnableUnmanagedDebugging

StartURL

IncrementalBuild

StartWithIE

Reference3   This object represents one project reference. The following property is not supported and accessing this property will throw an exception:

References   This object represents a collection of all the references in the macro project. The following methods are not supported, and calling one of them will throw an exception:

AddActiveX

AddProject

See Also

Reference

MacrosIDE

VSProject

Imports

VSProjectItem

BuildManager

VSProject2

Reference3

Concepts

Introduction to Project Extensibility