Generic vs. Language-Specific Project Models

Visual Studio add-ins are deprecated in Visual Studio 2013. You should upgrade your add-ins to VSPackage extensions. For more information about upgrading, see FAQ: Converting Add-ins to VSPackage Extensions.

Visual Studio provides two types of project models: a generic one and programming language-specific ones.

Generic Project Model

The generic project model is represented by the following types:

Object Name

Description

Projects collection

Represents all projects in the solution.

Project object

Represents a project in the solution.

ProjectItems collection

Represents all of the items in a specified project.

ProjectItem object

Represents an item in a specified project.

These objects allow you to manipulate projects of any language type in Visual Studio. Using them, you can:

  • Save or delete a project.

  • Create a new project item for a project, based on the Visual Studio templates.

  • Add project items to a project from existing files.

  • Remove project items from a project.

  • Open, save, and delete project items from a project.

Language-Specific Project Model

In addition to the generic project-related objects, a set of namespaces represents the programming language-specific project and project item properties. These namespaces are:

The main objects that represents language projects is VSProject and VSProject2. VSProject2 derives from VSProject, which in turn derives from Project. Project items are represented by VSProjectItem objects.

Programming Language

Namespaces

Visual C#

VSLangProj, VSLangProj2, and VSLangProj80.

Visual Basic

VSLangProj, VSLangProj2, and VSLangProj80.

Visual C++

Microsoft.VisualStudio.VCProject and Microsoft.VisualStudio.VCProjectEngine.

All programming languages

EnvDTE and EnvDTE80.

Since the language-specific objects derive from the generic ones, they work essentially the same, except that they give you access to any additional properties, methods, and events that cannot be accessed with the generic Project and ProjectItem objects.

For more information about how to use the language-specific project model, see Introduction to Project Extensibility.

Change for Visual Studio .NET Visual C++ Projects

In Visual Studio .NET and beyond, special handling for the ProjectItems collection for Visual C++ is no longer required. That is, while the Visual C++ Projects collection previously stored all Visual C++ project files in a flat list, now the files are stored hierarchically as they are in the other programming languages.

Since this change can affect your existing code, there is a way to emulate the old behavior in the new project-specific object model when trying to index the ProjectItems collection to determine whether or not a file is in the project. The primary difference is that you can now return to the DTE object model by calling .Object on a Visual C++ object.

[Visual Basic]

Dim proj as VCProject = DTE.ActiveSolutionProjects(1).Object
Dim fileColl as IVCCollection = proj.Files
Dim file as VCFile = fileColl.Item("MyFile.cpp")
Dim projItem as ProjectItem = file.Object

See Also

Tasks

How to: Programmatically Create Projects

How to: Programmatically Create Project Items

Other Resources

Controlling the Solution and Its Projects