c# - 通过自定义 msi 安装程序修改 app.config

标签 c# .net windows-installer app-config

我需要在 app.config 中创建一个地址字符串:

<client>
       <endpoint address="http://ServerName/xxx/yyy.svc"
                    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IClientIInfoService"
                    contract="DocuHealthLinkSvcRef.IClientIInfoService" name="BasicHttpBinding_IClientIInfoService" />
</client>

ServerName需要用户在安装时输入。 为此,我在安装程序中创建了一个新的 UI 对话框。我还编写了一个 Installer.cs 类并将 install () 重写为:

public override void Install(System.Collections.IDictionary stateSaver)
        {

            base.Install(stateSaver);

            string targetDirectory = Context.Parameters["targetdir"];

            string ServerName = Context.Parameters["ServerName"];

            System.Diagnostics.Debugger.Break();

            string exePath = string.Format("{0}myapp.exe", targetDirectory);

           Configuration config = ConfigurationManager.OpenExeConfiguration(exePath);

            config.AppSettings.Settings["ServerName"].Value = ServerName;

            config.Save();
        }
    }

但是我如何在我的 app.config 中使用这个 ServerName 来创建指定的字符串。 我正在研究 VS2010。

最佳答案

你可以使用 WiX (Windows Installer XML toolset)构建您的 MSI,在这种情况下,您可以使用 XmlFile用于更新服务器名称的实用程序标记:

  <util:XmlFile Id="UpdateServerName" File="[INSTALLLOCATION]AppName.exe.config" Action="setValue" ElementPath="/client/endpoint" Name="address" Value="http://[SERVERNAME]/xxx/yyy.svc" />

您可以在安装期间使用 WixUI 捕获服务器名称扩展表单。

WiX 的优势:WiX 兼容 msbuild(与 .vdproj 文件不同),并且可以让您对安装程序进行更细粒度的控制,among other things

关于c# - 通过自定义 msi 安装程序修改 app.config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14135364/

相关文章:

c# - .Net、C# 和开源运动

wix - 64 位操作系统要求安装条件不会在 32 位 Windows 操作系统上失败

c# - 如何在 Window 启动 C# 时将 wpf 应用程序移动到最小化托盘?

wix - 升级 MSI 中包含的内容

c# - 下拉列表 "SelectedIndexChanged"事件中的错误,同时从 RadComboBox 选择新项目

c# - 从 Node 监听 Co​​nsoleTraceListener 日志

c# - 表达式查询中的动态 Lambda 表达式

c# - 匿名函数和局部变量

c# - 为什么我的动态值字典迭代(并行)丢弃了我的本地范围变量?

c# - 在模式对话框关闭时更新父页面?