configuration - 从 WIX 设置更新 app.config?

标签 configuration windows-services wix installation

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

<?xml version="1.0" encoding="UTF-8"?>



<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>

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

和示例会很棒!

编辑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>

最佳答案

您可以在安装程序项目中添加对 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]" />

请注意,您需要设置 .config 文件的目录和名称(您可以只使用 $(var.ProjectName.TargetFileName).config 这应该会自动为您解决

关于configuration - 从 WIX 设置更新 app.config?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13967551/

相关文章:

iis-7 - Wix 3.5 和 IIS7 - WriteIIS7ConfigChanges 失败 - 虽然尝试将三个 Web 应用程序作为虚拟目录安装到默认网站

wix - 无法使用 wix 安装程序更新明智的安装程序包

c# - WIX ComponentGroup 子目录

asp.net-mvc - 通过 ASP.NET MVC Controller 更新 AppSettings

f# - Topshelf.Fsharp 安装命令不执行任何操作

java - jooq:如何为静态 DSL 方法配置方言?

c# - 无法在计算机 '.' 上打开 <MyService> 服务

c++ - 如何知道哪个用户帐户运行特定的 Windows 服务?

java - Spring boot YAML 配置未读取所有值

grails - 为什么在插件的配置中未定义Config.groovy变量?