How to modify .NET config files during installation?
Asked Answered
O

5

41

I use the app.config file to store some values (path to a mapping database, data connection selections). These settings differ on the user machines and I would like the installer to set them right. Is there an installer that can work with .NET config files during setup and allow me to create some dialogs that would help me fill in these values ?

I know this question may be similar to : Initializing user.config or app.exe.config during install, but I am not limited to VS 2008 setup project and I want to change the settings in the config files.

EDIT: I see that using WIX is one option, but I feel like cracking a walnut with a sledgehammer. It may be the only solution, but I still hope for something simple.

Overline answered 14/11, 2008 at 10:59 Comment(0)
S
63

We use WIX to change the application's configuration file. It works really well, you'll need to add wixUtilExtension.dll in the reference.

WIX sample:

<Component Id="ChangeConfig" Guid="[YOUR_GUID_HERE]">
   <File Id="App.config" Name="MyApplication.exe.config" Vital="yes" KeyPath="yes" Source="[Path to project dir]\app.config" />
   <util:XmlFile Id="AppConfigSetConnStr" Action="setValue" Permanent="yes" File="[#App.config]"            
        ElementPath="/configuration/connectionStrings/add[\[]@name='MyDatabaseName'[\]]" Name="connectionString" 
        Value="Your Connection string values here" />

</Component>

It actually depends on what you are using to create the installer, What are you using ?
Have alook at the WIX Tutorial.

Subscript answered 14/11, 2008 at 15:15 Comment(4)
Thank you. I am still daunted by the WIX features and complexity. I am bit afraif to go that route yet for something so simple :)Overline
Just for completeness; if you're doing this in VS, you need to change the <Wix> tag at the top of the Fragment to include an attribute: xmlns:util="schemas.microsoft.com/wix/UtilExtension. You also need to add a reference to WixUtilExtension.Contradistinction
That's what I meant be saying adding the reference to the wixUtilExtension.dll in the reference. Yes you do have to do what you mention.Subscript
Can you do this such that old values from a previous version of the app.config are picked up and merged into the new app.config? Basically imagine a user installs version 1. Manually changes some of the appSettings. On version 2 upgrade we want to keep any changes to appSettings but overwrite everything else.Daimon
S
3

If you're using a VS setup project, have you created a custom action? I've used them for everything from poking XML values to deploying databases.

Sidewinder answered 14/11, 2008 at 18:22 Comment(2)
The VS Setup projects are not anything I'd recommend. They were resuscitated, but are still not supported in CI scenarios and are based on technologies from the VS2005 era and were never updated with proper MsBuild support.Hyland
@Hyland Considering that this answer is 7.5 years old, the technology has changed quite a bit.Sidewinder
P
1

I used NSIS with an XML plugin to do this.

Pd answered 14/11, 2008 at 18:19 Comment(0)
L
0

I've used the WIX toolset to produce an msi. The tool allows you to declaratively specify changes to XML files like app.config during installation. Problem is though there is a significant learning curve. Search sourceforge for wix.

Lycanthrope answered 14/11, 2008 at 11:10 Comment(1)
I was hoping for a lighter solution for medium / small projects ... :)Overline
M
0

I know this is an old question but we didn't want to use WIX either for a very simple little installer. I found this article that explains in a lot of detail exactly how to do it. It worked perfectly for us.

http://www.c-sharpcorner.com/UploadFile/ddoedens/CustomUI11102005042556AM/CustomUI.aspx

Met answered 9/2, 2016 at 21:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.