Home > c#, Windows Forms > Setup App.Config during .msi install, msi re-installing

Setup App.Config during .msi install, msi re-installing

The Issue

I wrote a windows form application that deployed  via an .msi installer.

The application has an App.Config file which contains a single configuration value. I wanted to prompt the user for this value during the installation wizard and write it to the application.exe.config file as part of the installation process.

I used the built in Setup project in Visual Studio 2010.

The solution

I could write it all here in my post but I have found one that was created earlier:

http://raquila.com/software/configure-app-config-application-settings-during-msi-install/

I essentially implemented the same solution but I wrote my .config file using a StringBuilder and deleted and re-wrote the.config file in the Post install custom action.

The other thing is that I created short cuts to the application by right-clicking on the primary output and chosing “Create Shortcut”, then I copied this to the desktop and users program menu locations.

The problem

I was installing this for “Everyone” and it would work fine for me, but when other people logged in and tried to launch the program the .msi would run and the application.exe.config file was being overwritten with the orginal version that was deployed with the .msi, which does not contain the users input.

The Fix

The problem is complicated and is related to the application short-cut.

It appears that by default the short-cuts created in the msi are “Advertised ShortCuts”.

According to microsoft when an advertised shortcut is activated “.. the installer verifies that all the components in the feature are installed before launching this file”.

This means that if you delete any of the files that were deployed to the installation location then the .msi will attempt to fix them and re-install the missing components, which in my case means that the application.exe.config is overwritten.

You can identify the “Advertised” short cut by looking at the “Properties” of a short-cut and the “Target” will be greyed out.

I found the post below that identifies an easy way to disable advertised shortcuts.

You need to set the “DISABLEADVTSHORTCUTS” property on the .msi. This can be done easily in the installer, I have my custom UI that is getting details from the user for the “Edit1Property” so in the Edit2Property I set these values and keep it invisible.

  • Edit2Property: DISABLEADVTSHORTCUTS
  • Edit2Value: 1
  • Edit2Visible: false

This updates the property table in the .msi and now all your short-cuts will be normal standard shortcuts.

http://social.msdn.microsoft.com/forums/en-US/winformssetup/thread/b0a3e6d5-38f0-4a37-9418-dd8d9297ef97/

Cheers 🙂

Final Tip: Setting the shortcut icon

Another tip is to set the icon based on the icon embeded in your .exe.

  • In the File System Editor, click on the ShortCut and view the properties
  • Click on the icon property
  • choose browse,
  • change from .ico to .exe
  • browse to the “Primary-Output for…” and choose OK.

It will show you the icons embeded in your .exe and this way you don’t need to deploy a seperate .ico file.

Advertisements
Categories: c#, Windows Forms
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: