在安装过程中初始化user.config或app.exe.config [英] Initializing user.config or app.exe.config during install

查看:205
本文介绍了在安装过程中初始化user.config或app.exe.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个.NET WinForms应用程序,它依赖于user.config来存储各种有用的设置,如内部网Web服务URL。我们希望可以在安装过程中导入自定义初始设置。这样的用例是,如果一家公司有100台机器,他们想要安装该软件,并且他们都应该参考有关的内部网络Web服务,这不应该在所有机器上手动设置。 / p>

我们正在使用VS2008安装项目来生成安装包。



我们到目前为止的想法是使安装程序可以使用信息(来自模板)创建自定义的初始.config文件,然后将其放在原位置,而不是安装项目安装的默认文件。



但是,除了这些以外,我看不到这样做的一种方法:


  1. 将可执行文件名称编码为自定义安装程序操作(派生自System.Configuration.Install.Installer),以便使用ConfigurationManager类来确定.config文件路径。如果可执行文件名称更改,则需要手动更改安装程序。

  2. 滚动我们自己的配置类或文件/文件夹层次结构以存储设置。这将基本上阻止我们从.NET中提供的隔离机制(这也是这里的障碍)的优势,如果我理解正确。



有没有人知道任何替代方法,或者使上述两种可口的方法?



我担心答案可能是不要这样做,它失败机构的精神,滚动自己的设置导入机制。

解决方案

我认为这是你需要的: http://raquila.com/software/configure-app- config-application-settings-during-msi-install /


I am developing a .NET WinForms application which relies on user.config to store various useful settings such as intranet web service URLs. We would like to make it possible to import custom initial settings as part of the installation. The use case for this is if a company has 100 machines they want to install the software on, and they should all have a reference to the intranet web service in question, this should not need to be set up manually on all the machines.

We are currently using a VS2008 setup project to generate the install package.

Our idea so far has been to enable the installer to make a custom initial .config file with the information (from a template), and then put that in place instead of the default one that the setup project installs.

However, I can't see a way to do this other than these few:

  1. Hardcode the executable name into a custom installer action (deriving from System.Configuration.Install.Installer), in order to use the ConfigurationManager class to determine the .config file path. This would require manual changes to the installer if the executable name changes.
  2. Roll our own configuration classes or file/folder hierarchy to store the settings. This would basically bar us from the advantages of the isolation mechanism (which is also the obstacle here) that .NET provides, if I understand correctly.

Does anyone know of any alternatives, or of ways to make the above two palatable?

I fear the answer may be "don't do this, it defeats the spirit of the mechanism, roll your own settings import mechanism".

解决方案

I think this is what you need: http://raquila.com/software/configure-app-config-application-settings-during-msi-install/

这篇关于在安装过程中初始化user.config或app.exe.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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