Frode
Posts: 34
Joined: Thu Feb 26, 2009 3:11 pm

Update .config file

Hi,

have a problem here I can't figure out.
In my installer project I have an application .config file I have set as Version - Get from file (so it doesn't get overwritten when first installed), then I have a New XML file target with the same filename where I set the db configuration with the properties given in the UI - this part works very well :)
Now I need to add an XML element on upgrades, for this I added another element in the aforementioned XML file - but this doesn't result in anything. When thinking this a bit through - that actually is how thing should work :roll: otherwise my original settings would have overwritten the changes the users might have done since last install/upgrade on the connection string.

So - the question :D : How do I go about to insert a new element into an existing .config file on upgrade, where the file is part of the original install package.
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Update .config file

Hello,

You can follow this article to see how to update your .config XML file.

Regards,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Frode
Posts: 34
Joined: Thu Feb 26, 2009 3:11 pm

Re: Update .config file

Well, I have read that article, and to be honest it doesn't elaborate much about the difference between an upgrade and an install.

In both circumstances the file will exist before the XML update process starts, so how do I differentiate the actions between this two situations?
Frode
Posts: 34
Joined: Thu Feb 26, 2009 3:11 pm

Re: Update .config file

For all that I know - that I have set "Install new version first and then uninstall old version" might have some implications here.
octavian.vasilovici
Posts: 51
Joined: Tue Jan 25, 2011 2:43 pm

Re: Update .config file

Hello,

From what I understand you should consider the following cases :

1. Clean Install of the current package. In this case there isn't a previous version installed on the machine. Therefor you will need to create the .config file when installing the package containing all the elements.
2. Upgrade. In this case an older version of the application is found on the machine. From what I understand you want to
insert a new element into an existing .config file on upgrade, where the file is part of the original install package
.

These two cases can be easily treated by using the New XML File operation from Advanced Installer with the following settings :

- Create a new XML File operation and keep the original settings.
- Add the element you want to add during the upgrade process ( and the installation process of the current package) and set the following settings:
xml_element.JPG
xml_element.JPG (37.64 KiB) Viewed 14849 times
The element will be created if it doesn't exists (during installation) or will be updated ( during upgrade).

If you have any other questions, please don't hesitate to ask us.

Best Regards,
Octavian.
_______________________________________________________________________________________________________________________________________________
Octavian Vasilovici
Advanced Installer Team
http://www.advancedinstaller.com/
Octavian Vasilovici - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Frode
Posts: 34
Joined: Thu Feb 26, 2009 3:11 pm

Re: Update .config file

Hi,

and thank you for your answer, but my situation is a bit more complex :?

I have set the component for the config file to Never Overwrite to prevent overwriting of user modified config files, this setting also seems to prevent the New/Edit XML file operation for doing its work.

In my New/Edit XML file operation I do two things, first I update the db connectionstring (which should only be done on install), then I add a new element (which didn't exist before version 5 of the product).

Can you please confirm that the following would be the correct way to solve this, without screwing up any user modification to the config:

* remove both of this elements from the initial (the installed) config file
* set create element if it doesn't already exist for the connectionStrings->add, attribute name = ConnectionString set as key, attribute connectionString = valuex=[propertyX] etc.
* set create element if it doesn't already exist for the appSettings->add, attributes as required
* don't set never overwrite on the component for the config file
* set Attribute Vital and File Version Get from file for the config file (this should ensure the file is installed but never overwrite an existing file)

or can this create problems under certain circumstances?

Sincerely
Frode
octavian.vasilovici
Posts: 51
Joined: Tue Jan 25, 2011 2:43 pm

Re: Update .config file

Hello Frode,
I have set the component for the config file to Never Overwrite to prevent overwriting of user modified config files
This setting doesn't prevent the user to modify the file. The User Guide states:
"The component is not installed or reinstalled, if a key path file or a key path registry entry for the component already exists. This affects only future installers which try to overwrite the component key path, it doesn't affect already installed resources."
This is related only when Installing components. Updating an XML file is not restricted.

The approach you are looking for is this :

- Add the XML file in Advanced Installer in "Windows Installer" format. Open it with the XML Editor. The file will display all the elements of your imported file.
- Add your new element.
- Update your older element's attribute.
- You can delete the elements that you don't want to be modified.

How it will work:
The elements found different will be updated or removed based on your settings, the ones missing will be added.
There is no need to do this:
* remove both of this elements from the initial (the installed) config file
* set create element if it doesn't already exist for the connectionStrings->add, attribute name = ConnectionString set as key, attribute connectionString = valuex=[propertyX] etc.
* set create element if it doesn't already exist for the appSettings->add, attributes as required
* don't set never overwrite on the component for the config file
If you have any other questions, please don't hesitate to ask us.

Best Regards,
Octavian.
_______________________________________________________________________________________________________________________________________________
Octavian Vasilovici
Advanced Installer Team
http://www.advancedinstaller.com/
Octavian Vasilovici - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”