Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force overwrite of App.config during installation

Tags:

We currently have 4 installers for our client software:

  • ClientSetupTest
  • ClientSetupProduction
  • ClientUpdateTest
  • ClientUpdateProduction

The only differences between them are that Setup contains the Crystal Reports redistributable files, and Update doesn't. Test and Production just specifies which environment they run in and the only difference there is one line in the Client.exe.config file.

Dumb, I know, which is why I replaced them all with one installer after getting rid of Crystal Reports. The new installer writes the selected environment out to setup.config, which is referenced by the file attribute (see here).

The "file" attribute is new to the config file with this new installer. The problem I'm running into is that if we modify the Client.exe.config file on an old installation, then run the new installer, the config file never gets updated with the "file" attribute.

Is there any way to force it to update a file? RemovePreviousVersions doesn't exactly work, since it's a different installer, unless I'm misunderstanding something. My current idea, which will probably work, is to add code in the OnBeforeInstall method to rename the old Client.exe.config to a backup file, so it'll always write the new one. Seems like there should be a simpler solution within the installer itself, though. Any ideas?

EDIT: Renaming the old config file to Client.exe.config.old before calling base.OnBeforeInstall() didn't work. It renamed the file, but never wrote the new one.

like image 893
Chris Doggett Avatar asked Jul 29 '09 15:07

Chris Doggett


People also ask

How do I install an app release config file?

To add an application configuration file to a C# projectIn Solution Explorer, right-click the project node, and then select Add > New Item. The Add New Item dialog box appears.

What is app config file?

An application configuration file is an XML file used to control assembly binding. It can redirect an application from using one version of a side-by-side assembly to another version of the same assembly. This is called per-application configuration.

Where is app config file?

The application configuration file usually lives in the same directory as your application. For web applications, it is named Web. config. For non-web applications, it starts life with the name of App.


1 Answers

Windows Installer won't update a modified file.

Nonversioned Files are User Data—If the Modified date is later than the Create date for the file on the computer, do not install the file because user customizations would be deleted. If the Modified and Create dates are the same, install the file. If the Create date is later than the Modified date, the file is considered unmodified, install the file.

You have some options:

  • include a custom action that modifies the file in place. This might be a script or .NET code.

  • do as you say - move the existing file out of the way. The installer won't stop on it. But you need to make sure it happens in the order you are imagining. You may need Orca to figure out the ordering.

  • include a custom option to set the create date to be "today". This should be really simple with a scripted custom action, using the Scripting.FileSystemObject. Then Windows installer will overwrite it.

like image 149
Cheeso Avatar answered Oct 05 '22 13:10

Cheeso