从WIX设置更新app.config?

Ban*_*hee 5 installation configuration windows-services wix

我正在尝试Wix 3.6,这就是它现在的样子:

<?xml version="1.0" encoding="UTF-8"?>
Run Code Online (Sandbox Code Playgroud)

<Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="myappINSTALLDIR" Name="myapp5Service">
        <Component Id="SampleServiceComponent" DiskId="1" Guid="6f51c0f3-776c-4aec-a200-1f199352c6c3" Win64="yes">
          <File Id="myapp5.WindowsService.exe" Name="myapp5.WindowsService.exe" Source="$(var.myapp.WindowsService.TargetDir)\myapp5.WindowsService.exe" KeyPath='yes'/>
          ...

          <ServiceInstall Id="InstallmyappService" DisplayName="myappService" Name="myapp5.WindowsService.exe" Description="myapp 5 Service - För effektivare och enklare operationsplanering" Account="LocalSystem" ErrorControl="normal" Start="auto" Type="ownProcess" Vital="yes" />
          <ServiceControl Id="ControlmyappService" Name="myapp5.WindowsService.exe" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
        </Component>
    </Directory>
</Directory>


<WixVariable Id="WixUIBannerBmp" Value="$(var.ProjectDir)\Image\myappTopBanner.bmp" />
<WixVariable Id="WixUIDialogBmp" Value="$(var.ProjectDir)\Image\myappDialogBackground.bmp" />

<Property Id="WIXUI_INSTALLDIR" Value="myappINSTALLDIR" />
<UIRef Id="WixUI_InstallDir" />

<Feature Id="ProductFeature" Title="Wix_myapp.WindowsService" Level="1">
  <ComponentRef Id="SampleServiceComponent" />
</Feature>
<Media Id="1" Cabinet="SampleServiceComponent.cab" EmbedCab="yes" />
</Product>
Run Code Online (Sandbox Code Playgroud)

现在我需要在Wix设置中添加一个对话框,其中一个appSetting和一个baseadress(WCF)设置为app.config.这大部分都是在安装之前完成的,因为它将决定Wix安装的Windows服务的名称.

而exampel会很棒!

编辑1:

    <WixVariable Id="WixUIBannerBmp" Value="$(var.ProjectDir)\Image\myappTopBanner.bmp" />
<WixVariable Id="WixUIDialogBmp" Value="$(var.ProjectDir)\Image\myappDialogBackground.bmp" />

<Property Id="SERVICEADDRESS" Value="http://serviceaddress"/>
<Property Id="WIXUI_INSTALLDIR" Value="myappINSTALLDIR" />
<UIRef Id="WixUI_InstallDir" />

<util:XmlFile Id="UpdateBaseAddress"
  Action="setValue"
  File="$(var.myapp.WindowsService.TargetDir)\myapp5.WindowsService.exe.config"
  SelectionLanguage="XPath"
  Permanent="yes"
  ElementPath="/configuration/applicationSettings/ServiceName"
  Name="baseAddress" Value="[SERVICEADDRESS]" />

<Feature Id="ProductFeature" Title="Wix_myapp.WindowsService" Level="1">
  <ComponentRef Id="SampleServiceComponent" />
</Feature>
<Media Id="1" Cabinet="SampleServiceComponent.cab" EmbedCab="yes" />
</Product>
Run Code Online (Sandbox Code Playgroud)

Dan*_*itt 9

您可以将WixUtilExtension.dll的引用添加到安装程序项目,然后使用XmlFile更新app.config,如:

<Property Id="SERVICEADDRESS" Value="http://serviceaddress"/>

<util:XmlFile Id="UpdateBaseAddress" 
  Action="setValue" 
  File="[DirApplication]$(var.app.config)"
  SelectionLanguage="XPath" 
  Permanent="yes"
  ElementPath="/configuration/applicationSettings/...."
  Name="baseAddress" Value="[SERVICEADDRESS]" />
Run Code Online (Sandbox Code Playgroud)

请注意,您需要设置目录和config文件的名称(你可以只使用$(VAR.项目名 .TargetFileName)的.config它应该自动做出来给你

  • @SnowJim,根据文档[`XmlFile`](http://wix.sourceforge.net/manual-wix3/util_xsd_xmlfile.htm)必须驻留在`Component`元素中. (4认同)
  • 请注意,要使用Daniel的答案,您需要通过将`xmlns:util ="http://schemas.microsoft.com/wix/UtilExtension"添加到根目录`<Wix />`元素来定义`util`. (4认同)
  • 不清楚的是何时触发此更改。这只会在安装过程结束时发生吗? (2认同)