RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Building Custom Installer Classes in .NET : Page 4

When it comes to installations, automation beats manual intervention hands-down every time. Learn how to build custom installer classes to automate setup tasks that Visual Studio setup projects don't handle automatically.

Providing Output
Use the LogMessage method to provide feedback from your installer. This is particularly useful when troubleshooting setup issues. Your output is stored in a log file and is also displayed in the command window when using installutil.exe. By default, the log file is stored in the same directory as your assembly with the same file name as your assembly and an .InstallLog file extension.

Avoid Unhandled Exceptions
If you allow exceptions to be thrown from your installer class, the calling application (your MSI setup) will fail. This is a particular problem if your installer class generates an exception during an uninstall, as it can make it impossible for users to uninstall your application. You should trap all exceptions, use LogMessage to record their details, and display on-screen messages as appropriate.

Setup Task Examples
The sample project includes a generic implementation of the installer class with a selection form and a status form. The sample displays the selection form to allow user selections and executes code to create a virtual directory, an event source for the application log, and a performance monitor category and counters.

Other Ideas
Here are some other ideas you may want to implement:

  1. Present a settings dialog and write settings to a configuration (.config) file. This could include user preferences, database connection settings, or anything else you may need. You can use this method to avoid overwriting an existing configuration file when you re-run setup by checking for an existing file before writing out a set of default settings.
  2. Register your application online.
  3. Automatically check for upgrades (see the article Automatically Upgrade Your .NET Applications On-the-Fly)
  4. Perform custom uninstall clean-up actions like temporary file deletion to ensure your application uninstalls cleanly.
There are many application-specific tasks you need to execute at setup time. By using the installer class to write custom actions in .NET, you can code them in your chosen .NET language rather than in some vendor-specific third-party installer language. Doing it yourself lets you make the best use of your development skills and provides the means to reuse your code in your application. For example, it's often desirable to use parts of your setup code from within your application for configuration or preferences forms.

Using an installer class in .NET is easy and gives you the essential flexibility you need to perform tasks at setup time.

Anthony Glenwright is the Product Development Manager at Inventua for TrueTeam, a collaboration tool which manages and integrates the workflows of running a successful software organization. You can contact him through his Web site at www.inventua.com or directly.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date