Roh*_*ews 2 .net c# 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>
Run Code Online (Sandbox Code Playgroud)
在ServerName需要由用户在安装过程中输入。为此,我在安装程序中创建了一个新的UI对话框。我还编写了一个Installer.cs类并覆盖了install ()as:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
但我怎么用这个ServerName在我app.config创建指定的字符串。我正在研究VS2010。
您可以使用WiX(Windows Installer XML工具集)来构建MSI,在这种情况下,您可以使用XmlFile实用工具标签来更新服务器名称:
<util:XmlFile Id="UpdateServerName" File="[INSTALLLOCATION]AppName.exe.config" Action="setValue" ElementPath="/client/endpoint" Name="address" Value="http://[SERVERNAME]/xxx/yyy.svc" />
Run Code Online (Sandbox Code Playgroud)
您可以使用WixUI扩展名表单在安装过程中捕获服务器名称。
维克斯的优点:维克斯是兼容的MSBuild(不像.vdproj文件),并为您提供了更细粒度的控制你的安装程序,除其他事项外