Aaron Stebner's WebLog

Thoughts about setup and deployment issues, WiX, XNA, the .NET Framework and Visual Studio

Building setup packages for Visual Studio project templates and starter kits

Building setup packages for Visual Studio project templates and starter kits

  • Comments 1

This article describes how to create an MSI-based setup package to install project templates, item templates and starter kits for use with Visual Studio.  It uses a real-world example to demonstrate key concepts for building a robust, reliable installer package.

Payload included in a project template setup package

  • Zero or more project template ZIP files
  • Zero or more item template ZIP files
  • Zero or more new file items

The example I have created installs a Visual Basic 2005 project template, a Visual Basic 2005 item template, a Visual Basic 2005 new file item, a Visual C# 2005 project template, a Visual C# 2005 item template and a Visual C# 2005 new file item.

Actions performed in a project template setup package

  1. Validate that the user launching setup has administrative privileges
  2. Validate that at least one of the Visual Studio editions supported by the project template is installed on the system prior to allowing the installer to run
  3. Locate the Visual Studio installation directory so the installer knows where to install the project template files
  4. Locate the Visual Studio IDE executable (devenv.exe) and the Visual Studio Express Edition IDE executables (vbexpress.exe, vcexpress.exe, vcsexpress.exe, vjsexpress.exe and vwdexpress.exe)
  5. Install the files to the appropriate Visual Studio and/or Visual Studio Express Edition project and item templates folder
  6. Launch the Visual Studio IDE executable and the Visual Studio Express Edition IDE executables with the /setup parameter to update the Visual Studio project and item template caches so the new items will appear in the IDE UI

How to build and run the example project template setup package

You can use the following steps to download, build and run the example project template setup package that I have created:

  1. Create a directory named c:\wix on your system
  2. Download the latest WiX version 2.0 binaries ZIP file from this location and extract the contents to c:\wix on your system
  3. Download the WXS file and build script that I created from this location and extract the contents to c:\wix on your system
  4. Run the build script named build_project_template_example.bat.  After running this batch file, you should see an MSI named project_template_example.msi in the folder c:\wix\build
  5. Install Visual Studio 2005, Visual Basic 2005 Express Edition and/or Visual C# 2005 Express Edition
  6. Install project_template_example.msi
  7. Launch the Visual Studio edition(s) you installed in step 5 above and verify that the project and item templates appear in the Visual Basic and Visual C# categories

More details about the design of a project template setup package

There are some important design considerations that have been applied while creating this example project template setup package:

  • I decided to support Visual Studio 2005 and the Visual Basic 2005 and Visual C# 2005 Express Editions for the project and item templates.  As a result, the setup package performs detection for all 3 products, and installs the templates to the proper location depending on which products are found on the user's system.  It is possible for the user to have any or all of these editions of Visual Studio installed on the same system, and the setup package correctly handles all of those install permutations
  • If none of the supported Visual Studio editions are found on the system, the setup will not allow the user to install
  • Within Visual Studio 2005 setup, it is possible to uncheck and not install the language tools.  As a result, the example setup package I created not only checks for the existence of Visual Studio 2005, but also checks to make sure that the Visual Basic and Visual C# language tools were installed as part of Visual Studio 2005 setup
  • A user could install Visual Studio 2005 to a non-default path, so the example setup package looks up the exact install location of Visual Studio 2005 so it will correctly support cases where Visual Studio 2005 is installed to a non-default path
  • The installer includes custom actions that cause Visual Studio to refresh the project and item template cache.  There are 2 sets of custom actions - one for the install/repair scenario and the other for the uninstall scenario.  I created 2 sets of custom actions so that the installer can check for success in the install/repair case, but it can also ignore the return code and not block uninstall if the custom action fails
  • The installer includes some progress strings that are displayed on the setup progress page when the custom actions are executing.  Without these strings, setup would appear to be hung during the custom action.  These custom actions can take a little while to complete, so it is advisable to add these progress strings to your setup as well

Using the example as a starting point for your own setup package

The file project_template_example.wxs that is included in the example zip file contains detailed comments describing the key features of the setup, and it is designed to help you get started creating your own project template setup package.  Here are a couple of key points to keep in mind as you get started creating your own project template setup package:

  • This is very important - do NOT use any of the GUIDs in project_template_example.wxs as part of your setup.  If you do so, you will end up violating the Windows Installer component rules, which causes problems for installing and uninstalling products.  Additional information about the component rules can be found in this blog post by Rob Mensching (which is highly recommended reading if you are building MSI packages)
  • The example I created targets Visual Studio 2005, and the detection methods for the Visual Studio IDE and Visual Studio Express Edition IDE executables are all specific to the Visual Studio 2005 product family.  I have created WiX fragments that can be used to detect all of the Visual Studio 2005 Express Editions and the 5 major language tools within Visual Studio 2005 (Visual Basic, Visual C++, Visual C#, Visual J# and Visual Web Developer).  The WiX 2.0 fragments are located here, and the WiX 3.0 fragments are located here
  • If you plan to target older versions of Visual Studio (such as Visual Studio .NET 2002 or 2003) for your project templates, you will need to create your own detection mechanisms that are similar to the examples I posted for Visual Studio 2005

<update date="5/15/2009"> Fixed broken links to the sample files used in this post. </update>

 

  • When I started working on the Windows Media Center SDK setup for Windows Vista, I did some research to...
Page 1 of 1 (1 items)
Leave a Comment
  • Please add 1 and 3 and type the answer here:
  • Post