The Solution Object

 < Free Open Study > 



Overview

Hank Aaron, while at bat, was asked by Yogi Berra, "Can't you read? Your bat's upside down". Aaron hit the ball over the fence, turned to Berra, and said, "Didn't come up here to read. Came up here to hit".

At this point in the book, you have seen how to manipulate forms and their associated controls. You have seen how to manipulate code in the Text Editor window. You have learned how to perform these actions through the use of macros and in an add-in. In this chapter you'll learn how to manipulate the solution and its project(s). At the end of the chapter, you'll explore some of the other items within the IDE, such as the ToolBox and TaskList objects.

The Visual Studio .NET automation model provides objects and collections that allow you to control both the solution and the projects, and the project items within the solution. The Solution object and the Solution.Projects collection contain all of the projects in the current solution.

Only one solution can be open in the Visual Studio .NET IDE at one time. That solution must contain at least one project. You certainly are not limited to one project. In VB 6.0, if you wanted to debug one or more DLLs, you had to have an instance of the client application that called the first DLL. Additionally, you had to have another instance of the IDE for each DLL that would be called in a series. In Visual Studio .NET, you can have numerous projects in a solution. Therefore, you can debug a client application calling a series of DLLs in one instance of the IDE. Obviously then, the projects can be of various types. Furthermore, they can be written in various languages. For example, a solution might contain a Visual Basic .NET Windows application project and a Visual C# class library (DLL) project. Each project contains one or more project items, such as classes, modules, forms, and so forth.

The Solution object is the key object that facilitates the manipulation of all of these objects. Using the Solution object you can do the following:

  • Create a new solution.

  • Add new projects to the solution using a Visual Studio .NET template.

  • Add existing projects to the solution.

  • Remove a project from the solution.

  • Open, save, close, and build the solution.

Visual Studio .NET provides a generic project model. By this I mean that an add-in written in any of the Visual Studio .NET languages that support the automation model can manipulate the project model. The project model is composed of the objects listed in Table 9-1.

Table 9-1: Project Object Model

OBJECT NAME

OBJECT DESCRIPTION

Projects collection

A collection of all projects in the solution

Project object

Represents one project in the Projects collection or the solution

ProjectItems collection

Collection of all of the items in a project

ProjectItem object

Represents an item, such as a class, form, and so forth, in a specified project

These objects allow you to build an add-in using any Visual Studio .NET language. In the add-in, you can create a new project, save or delete an existing project, and add or remove project items to and from a project.

In addition to the generic project objects available to all languages, each language provides its own custom project objects. These are the VBProject, VCProject, and CsharpProject objects, which represent their respective languages (VB, C++, and C#).

You can reference these language-specific objects by a reference such as DTE.VBProjects or DTE.GetObject("VBProjects") to retrieve the VB-specific project object.



 < Free Open Study > 



Writing Add-Ins for Visual Studio  .NET
Writing Add-Ins for Visual Studio .NET
ISBN: 1590590260
EAN: 2147483647
Year: 2002
Pages: 172
Authors: Les Smith

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net