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

查看:22
本文介绍了如何在安装过程中修改 .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天全站免登陆