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, by switching to the “user interface editor” and adding a custom textbox page to the UI. This does mean that you will have an empty step in your installation however, so think of some nice use for it like a warning message about this being a free product??
I acutally 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, (otherwise you would set it in Edit1Property)
- 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.
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.