search
Japanese Chinese Nederlands Espanol Italiano Deutsch Francais Twitter Rss Feeds
MicrosoftArticlesForumsFAQs
C# .NET
VB.NET
Visual Studio .NET
ADO.NET
Xml / Xslt
VB 6.0
.NET CF
GDI+
LINQ
Deployment
Security
FoxPro
Silverlight / WPF
Entity Framework
RIA Services

Web ProgrammingArticlesForumsFAQs
JavaScript
ASP
ASP.NET
Web Services

Non-MicrosoftArticlesForumsFAQs
NHibernate
Perl
PHP
Ruby
Java
Linux / Unix
Apple
Open Source

DatabasesArticlesForumsFAQs
SQL Server
Access
Oracle
MySQL
Other Databases

OfficeArticlesForumsFAQs
Excel
Word
Powerpoint
Outlook
Publisher
Money

Operating SystemsArticlesForumsFAQs
Windows 7
Windows Server
Windows Vista
Windows XP
Windows Update
MAC
Linux / UNIX

Server PlatformsArticlesForumsFAQs
BizTalk
Site Server
Exhange Server
IIS

Graphic DesignArticlesForumsFAQs
Macromedia Flash
Adobe PhotoShop
Expression Blend
Expression Design
Expression Web

OtherArticlesForumsFAQs
Subversion / CVS
Ask Dr. Dotnetsky
Active Directory
Networking
Uninstall Virus
Job Openings
Product Reviews
Search Engines
Resumes

 

Build a Custom Action InstallHelper Configuration Editor


By Peter Bromberg
Printer Friendly Version
View My Articles
18 Views
    

When you build an MSI Installer for your project using the Visual Studio built - in Setup Project types, the support for custom editing of configuration settings and / or performing additional installation - related tasks is limited. Here is an easy way to "soup it up".


With the built-in Visual Studio Setup projects, there are some UI elements that can be configured and outputs captured, but in general my opinion is that they are rather clumsy to use. You can certainly spend some money for a third party installation framework and get a lot more horsepower to do what you need.

In some cases however, you may only need to  allow the user who is installing your product to change some existing settings, during the installation, and if this is the case, then read on - I have an easy solution for you.

This all came about because this morning my erstwhile site partner and I were discussing this very subject. He needed to be able to update versioned SQL Server database schemas, and I needed to allow my users to modify connection strings and other items related to how their new XYZ thingy service operated on their ABC machine, or differently on their DEF machine, and so on.

The trick to all this is to use the Custom Actions facility of the installer project. You can  have the MSI Installer run an executable of your own design at this stage, and when it is done, the installation will complete and your user will be happy because they've been able to modify their desired runtime settings. The only other trick you need to know is how to pass the path to your main installed executable so that your Custom Action exe can pick it up and be able to know where to load your configuration file so it can be modifed. This is done in the Properties sheet for the Custom Action Commit folder where you'll have an item pointing to your InstallHelper utility that I give you here.

In order to set this up, I rolled the "InstallHelper" Windows Forms app. What this does is load your ABC.exe.config file that the installer just dropped into the deployment folder, iterate over all the appSettings elements, and dynamically create a set of labels and TextBoxes holding the key and value attributes respectively, allowing your user to modify the values of any or all of your settings. Then, all they need to do is press the COMMIT button and it saves the modified config file, closes the InstallHelper app, and your installation completes perfectly - now with the user's custom settings as desired.

The "Install Helper" does not need to derive from Installer. All it needs to know is how read and manipulate the command line. Moreover, this technique can be used for a lot of other things besides just modifying the configuration file - you can prompt the user to load a specific SQL Script and enter a connection string and then perform a database version update, for example.

Rather than get into a lot of code with this, I think it is more productive just to put my prototype here for download, and you can experiment with it yourself.  The downloadable Visual Studio 2005 solution includes my InstallHelper exe project, a "TestProject", and an installer project to install the TestProject. 

The most important part is to get the path correct in the Properties of the Custom Actions Commit item properties. In this case, I use built-in installer variables which will expand at installation to the actual path to the installed exe:



You add the Installer variables as shown, and the full name of your Executable whose config file is to be modified. These entries go in both Arguments and CustomActionData fields.  The example here looks like this:  [ProgramFilesFolder][Manufacturer]\[ProductName]\TestProject.exe  What this does is pass the expanded full path to the command line of InstallHelper.exe, so it knows where to find the config file to load.

Build your installer.  At install time, Install helper will come up and automatically read all your appSettings elements, and dynamically create a label and textbox for each so user can edit. Press COMMIT button to save, and the install will complete. Here's a sample:

You can download the full solution here


 


Biography - Peter Bromberg
Peter Bromberg is a C# MVP, MCP, and .NET expert who has worked in banking, financial and telephony for over 20 years. Pete focuses exclusively on the .NET Platform, and currently develops SOA and other .NET applications for a Fortune 500 clientele. Peter enjoys producing digital photo collage with Maya,playing jazz flute, the beach, and fine wines. You can view Peter's UnBlog and IttyUrl sites.
Please post questions at forums, not via email!

button
Article Discussion: Build a Custom Action IinstallHelper Configuration Editor
Peter Bromberg posted at Tuesday, March 27, 2007 8:01 PM
Original Article
 

Execute Exe after Install
Gordon Weis replied to Peter Bromberg at Thursday, April 26, 2007 3:15 PM
I am going to download and look at your code - always good stuff. Is there a way to have the installer execute the application after it is installed? I looked and the option didn't just jump right out. Thanks for any help.
 

App Path Variable
Doug Simpson replied to Peter Bromberg at Monday, November 05, 2007 5:25 PM
I see why you renamed "Default Company Name" to "Manufacturer"... the spaces in the path are removed for some reason.  Have you figured out why this is and how to correct it?
 

Is there a reason for not using TARGETDIR
Julius Ræstad replied to Peter Bromberg at Friday, November 16, 2007 5:38 AM

Hi,

Is there are reason for not using "[TARGETDIR]\" instead of [ProgramFilesFolder][Manufacturer]\[ProductName]\. The TARGETDIR ensures with " ensures that all spaces are corect and the correct directory is used if the user decides to install the program in a different folder that the default one.