我需要在 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/