如何在安装过程中修改.NET配置文件? [英] How to modify .NET config files during installation?

查看:263
本文介绍了如何在安装过程中修改.NET配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用app.config文件来存储一些值(映射数据库的路径,数据连接选择)。这些设置在用户计算机上不同,我希望安装程序将其设置正确。是否有安装程序可以在安装过程中使用.NET配置文件,并允许我创建一些对话框,将帮助我填写这些值?

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 ?

我知道这个问题可能类似于:安装期间初始化user.config或app.exe.config ,但我不限于VS 2008安装项目,我想更改配置文件中的设置。

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.

编辑:我看到使用WIX是一个选项,但我觉得用大锤打开一个核桃。

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.

推荐答案

我们使用WIX来更改应用程序的配置文件。它工作得很好,你需要在引用中添加wixUtilExtension.dll。

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示例:

<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>

这实际上取决于您用来创建安装程序,您使用什么?
查看 WIX教程

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

这篇关于如何在安装过程中修改.NET配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆