简体   繁体   English

如何在安装过程中修改.NET配置文件?

[英]How to modify .NET config files during installation?

I use the app.config file to store some values (path to a mapping database, data connection selections). 我使用app.config文件来存储一些值(映射数据库的路径,数据连接选择)。 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 ? 是否有安装程序可以在安装过程中使用.NET配置文件,并允许我创建一些可以帮助我填写这些值的对话框?

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. 我知道这个问题可能类似于: 在安装过程中初始化user.config或app.exe.config ,但我不限于VS 2008安装项目,我想更改配置文件中的设置。

EDIT: I see that using WIX is one option, but I feel like cracking a walnut with a sledgehammer. 编辑:我看到使用WIX是一个选项,但我觉得用大锤开裂核桃。 It may be the only solution, but I still hope for something simple. 它可能是唯一的解决方案,但我仍然希望有一些简单的方法。

We use WIX to change the application's configuration file. 我们使用WIX来更改应用程序的配置文件。 It works really well, you'll need to add wixUtilExtension.dll in the reference. 它工作得很好,你需要在引用中添加wixUtilExtension.dll。

WIX sample: 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>

It actually depends on what you are using to create the installer, What are you using ? 它实际上取决于您使用什么来创建安装程序,您在使用什么?
Have alook at the WIX Tutorial . 已经参加了WIX教程

If you're using a VS setup project, have you created a custom action? 如果您正在使用VS安装项目,是否已创建自定义操作? I've used them for everything from poking XML values to deploying databases. 我已经将它们用于从挖掘XML值到部署数据库的所有内容。

I've used the WIX toolset to produce an msi. 我已经使用WIX工具集生成了一个msi。 The tool allows you to declaratively specify changes to XML files like app.config during installation. 该工具允许您以声明方式指定安装期间对app.config等XML文件的更改。 Problem is though there is a significant learning curve. 问题是虽然有一个重要的学习曲线。 Search sourceforge for wix. 搜索wix的sourceforge。

我使用带有XML插件的NSIS来做到这一点。

I know this is an old question but we didn't want to use WIX either for a very simple little installer. 我知道这是一个老问题,但我们不想将WIX用于一个非常简单的小安装程序。 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 http://www.c-sharpcorner.com/UploadFile/ddoedens/CustomUI11102005042556AM/CustomUI.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM