Walkthru:Creating an Installer 
Extensibility Guided Tour Send comments on this topic.
Walkthru:Creating an Installer

Glossary Item Box

Creating a Windows Installer Package

One of the great benefits of Windows Installer Packages is that they allow package authors to easily specify setup requirements and conditions necessary for installation. For example, deploying a VsPackage to a computer without Visual Studio simply wouldn't make sense. Part of authoring a Windows Installer Package, therefore, revolves around detecting previously installed components and in ensuring the existence of required libraries and other resources, as well as tackling versioning issues for the deliverable itself. Visual Studio Setup Projects provide a powerful way to interact with the target machine to establish contingencies prior to an installation. This allows a greater degree of success surrounding installations, and error messages to end-users can be exposed to inform them of missing key components or other resources – which end users are usually happier knowing about before they attempt to install a product. During setup on a target machine, key values about the target environment are made accessible in the form of signatures and component ids that can be easily evaluated programmatically before and during installation. For example, to detect if Visual Studio is running when an installation attempt is made, an Installer Package author needs only look for the VISUAL_STUDIO_RUNNING condition (this condition and others are defined in the VS SDK), with simple syntax such as NOT VISUAL_STUDIO_RUNNING. If the condition is not met, a corresponding error message (something telling the end user to close Visual Studio before proceeding) will be raised by the installation wizard, and the installer will be exited gracefully. The ability to simply evaluate and respond to launch and other conditions during setup helps ensure a better rate of success for package authors and a better overall experience for end users.

VsPackages and Visual Studio Versions

Authoring Installer Packages for VsPackages also requires authors to actively determine which versions of Visual Studio they wish to target. The VS SDK provides guidelines and best practice instructions for targeting various versions of Visual Studio – including the option of building and deploying VsPackages that run on multiple versions of Visual Studio on the same target computer (i.e. side by side installations). The Windows Installer Package can also easily allow package authors to evaluate which versions (such as VS 2002, 2003, or 2005) are installed, as well as which editions (e.g. Standard, Professional, Enterprise Architect, Team Developer, etc) are loaded. With this information available for easy evaluation, installers can be specifically crafted to target versions and editions of Visual Studio as needed.

Creating an Installer Package

In this walkthrough you will begin the process of creating a simple Installer Package built around the DevAnnotater extensibility sample created during the VSIP Walkthroughs. Note more advanced samples can require a more detailed installation process, see the SDK documentation for more details.

To begin creating a Windows Package Installer to redistribute DevAnnotater:

1.  Open the DevAnnotater Solution in Visual Studio.

2.  Right click the solution and select the Add | New Project menu option.

3.  In the Add New Project dialog box, in the Project Types pane, open the Other Project Types node, select Setup and Deployment, then select Setup Project in the Templates pane. Specify "DevAnnotaterPackage" for the Name for the Project and click OK.

4.  In the File System Editor, right-click the Application Folder and select Add | Project Output.

5.  In the Add Project Output Group dialog, ensure that the DevAnnotater project is selected in the Project drop-down list. Then select Primary output, and click OK.

6.  A warning about dependencies, like the one pictured below, may be displayed. If it is, just dismiss it.

7.  Select the Application Folder in the File System Editor and switch to the properties window. Locate the DefaultLocation property and set it to the following location:

[ProgramFilesFolder]\Contoso\DevAnnotater

At this point, the basic requirements of the Installer Package are now complete. However, you'll want to ensure that certain conditions are met when the Installer launches – to make sure that Visual Studio is installed, not running, etc. Checking for these conditions is handled by creating custom launch conditions – which are very easy to implement with Setup projects.

8.  In Solution Explorer, right click the DevAnnotaterPackage Project, and select the View | Launch Conditions menu option to load the Launch Conditions window.

9.  Right click on the Launch Conditions node, and select Add Launch Condition.

10.  Select the newly created launch condition (Condition1) in the Launch Conditions window, and then switch to the Properties window and set the following properties as indicated:

Name:         VS 2003 or VS 2005
Condition:   DEVENV_COMP_2003 OR DEVENV_COMP_2005
Message:    This is a VsPackage and Requires Visual Studio to be installed.

Changing these simple properties creates a Launch Condition that will ensure that Visual Studio 2003 or Visual Studio 2005 are installed on the target machine prior to launching the actual installation process. If the Condition does not evaluate to true, then the specified Message will be displayed to the end user.

11.  Once the first condition is added, create two more conditions by right-clicking and selecting Add Launch Condition, and then modifying the properties of the conditions as follows:

Name:         VS NOT RUNNING
Condition:   NOT VISUAL_STUDIO_RUNNING
Message:    Please close Visual Studio before continuing.

Name:         Elevated
Condition:   Privileged
Message:    This installation requires elevated permissions to continue.

12.  Select the Build | Rebuild Solution menu option to ensure that all of your changes compile correctly before continuing to the next walkthrough.

Page view tracker