How to modify .NET config files during installation?

前端 未结 5 768
有刺的猬
有刺的猬 2020-11-27 03:40

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 inst

相关标签:
5条回答
  • 2020-11-27 04:06

    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.

    0 讨论(0)
  • 2020-11-27 04:16

    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.

    0 讨论(0)
  • 2020-11-27 04:17

    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.

    0 讨论(0)
  • 2020-11-27 04:20

    I used NSIS with an XML plugin to do this.

    0 讨论(0)
  • 2020-11-27 04:25

    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

    0 讨论(0)
提交回复
热议问题