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.

Community
  • 1
  • 1
Tomas Pajonk
  • 5,132
  • 8
  • 41
  • 51

5 Answers5

64

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.

CheGueVerra
  • 7,849
  • 4
  • 37
  • 49
  • 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 :) – Tomas Pajonk Nov 14 '08 at 17:11
  • 20
    Just for completeness; if you're doing this in VS, you need to change the tag at the top of the Fragment to include an attribute: xmlns:util="http://schemas.microsoft.com/wix/UtilExtension. You also need to add a reference to WixUtilExtension. – Martin Clarke Oct 15 '12 at 09:58
  • 2
    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. – CheGueVerra Nov 07 '12 at 19:54
  • 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. – spartacus Jun 29 '21 at 19:34
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.

GalacticCowboy
  • 11,663
  • 2
  • 41
  • 66
  • 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. – jessehouwing Apr 23 '16 at 15:10
  • 2
    @jessehouwing Considering that this answer is 7.5 years old, the technology has changed quite a bit. – GalacticCowboy Apr 23 '16 at 17:44
1

I used NSIS with an XML plugin to do this.

ine
  • 14,014
  • 8
  • 55
  • 80
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.

tgeros
  • 2,592
  • 2
  • 18
  • 14
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

sjclark76
  • 394
  • 3
  • 8