【问题标题】:Passing build parameters to .wxs file to dynamically build wix installers将构建参数传递给 .wxs 文件以动态构建 wix 安装程序
【发布时间】:2010-01-06 21:45:04
【问题描述】:

我是一名学生开发人员,我已经为我现在合作的公司构建了几个安装程序。所以我对WIX相当熟悉。 我们最近决定有一个构建服务器来自动构建我们的解决方案。它构建调试和发布,以及混淆(和非混淆)项目。 你真的不必了解这些。您所要了解的是,我有相同的 Wix 项目动态构建不同的 MSI。 所以我们构建它们的方式是我们用几个参数调用 MSBuild.exe。 wix 项目所依赖的参数。

假设我们进入命令提示符并编写

C:\>\windows\Microsoft.NET\Framework\v3.5\MSBuild.exe MyApp.Install\MyApp.Install.wixproj /p:Configuration=Release /p:SpecialPath=Obfuscated /t:Build

这个想法是 wix 看到“SpecialPath”参数被分配“混淆”;并在安装程序路径中其源到 ..\myApp\bin\$(var.SpecialPath)\myApp.exe 在构建时转换为 ..\myApp\bin\Obfuscated\myApp.exe

问题

如何创建这些自定义构建参数并将它们传递给我的 .wxs 文件。到目前为止,使用 设置,$(var.SpecialPath) 尚未定义并且构建 CrashSplosions。

出于明显的法律原因,我不得不删除 90% 的 project.wxs 文件并重命名一些内容,但出于所有意图和目的,这就是我所拥有的。

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="myApp" Language="1033" Version="$(var.Version)" Manufacturer="myApp" UpgradeCode="$(var.UpgradeCode)">
<Package Id="*" InstallerVersion="200" Compressed="yes" />
<Media Id="1" Cabinet="media.cab" EmbedCab="yes" />

<Directory Id="TARGETDIR" Name="SourceDir" >
  <Directory Id="ProgramFilesFolder">
    <Directory Id="INSTALLLOCATION" Name="myApp"> 

      <Component Id="myAppEXE" Guid="FD5EBC02-MY29-GUID-ACCA-61324C5F1B68">
        <RegistryKey Root="HKLM" Key="Software\MyApp">
          <RegistryValue Value="0" Type="string" KeyPath="yes"/>
        </RegistryKey>
        <File Id="MYAPPEXE" Name='myApp.exe' Source="..\myApp\bin\$(var.SpecialPath)\myApp.exe" />
      </Component>

      <Component Id="EngineDLL" Guid="*">
        <File Id="ENGINEDLL" Name='Engine.dll' Source="..\myApp\bin\$(var.Configuration)\Engine.dll" />
      </Component>
      <Component Id="CommonDLL" Guid="*">
        <File Id="COMMONDLL" Name='Common.dll' Source="..\myApp\bin\$(var.Configuration)\Common.dll" />
      </Component>
      
    </Directory>
  </Directory>
</Directory>

<Feature Id="ProductFeature" Title="myApp" Description='All' Display='expand' Level="1" ConfigurableDirectory='INSTALLLOCATION'>
  <ComponentRef Id="myAppEXE" />
  <ComponentRef Id="EngineDLL" />
  <ComponentRef Id="CommonDLL" />
</Feature>
</Product>
</Wix>

【问题讨论】:

    标签: dynamic parameters build path wix


    【解决方案1】:

    它不适合您的原因是您在命令行上设置 msbuild 属性,这些属性没有作为 wix 变量传递。 MSBuild 属性和 wix 变量是两个不同的概念。

    解决此问题的一种方法是忽略 msbuild 属性的概念并使用环境变量将值直接传递给 candle.exe。您可以像这样在 wxs 文件中使用环境变量:

    $(env.SpecialPath)
    

    然后您可以从一个批处理文件启动您的安装构建,该文件准备了必要的环境变量,如下所示:

    @echo off
    setlocal
    
    set SpecialPath=foo
    set Configuration=Release
    set msbuild=C:\windows\Microsoft.NET\Framework\v3.5\MSBuild.exe
    
    %msbuild% test.wixproj /t:Build || goto ERROR
    
    exit /b 0
    
    :ERROR
    echo Failed to build setup!
    exit /b 1
    

    或者,如果您更喜欢通过 msbuild 属性传递参数,您应该首先查看msbuild candle task 文档。它表明您可以像这样在 wixproj 文件中设置值:

    <DefineConstants>Variable1=value1;Variable2=value2</DefineConstants>
    

    这仍然需要您在 wixproj 文件中硬编码值。如果您想在命令行上将值作为 msbuild 属性传递,那么您可能应该执行以下操作:

    <DefineConstants>Variable1=$(value1);Variable2=$(value2)</DefineConstants>
    

    然后在命令行传递/p:value1=foo /p:value2=bar,或者在别处定义这些msbuild属性。

    【讨论】:

      【解决方案2】:

      如前所述,您需要将变量传递到 WiX。我们使用 Nant 代替 MSBuild,但概念保持不变。

      这是一个将六个变量传递给蜡烛的 Nant 示例(这不是最简洁的示例,但从我从事的一个项目中逐字提取)

      <candle   out="${dir.obj}\"
                rebuild="true"
                extensions="WixUIExtension;WixNetFxExtension">
          <defines>
              <define name="ProcessorArchitecture" value="${release.platform}" />
              <define name="SourceDir" value="${dir.source}" />
              <define name="version" value="${version}" />
              <define name="releasetype" value="${release.type}" />
              <define name="Language" value="${language}" />
              <define name="product" value="${string.product}" />
              <define name="productedition" value="${release.productedition}" />
          </defines>
      
          <sources>
              <include name="*.wxs" />
              <include name="..\Common\*.wxs" />
          </sources>
      </candle>
      
      <!-- Define fallback culture for non-US -->
      <property name="cultures" value="${language}" />
      <property name="cultures" value="${language};en-US" unless="${language == 'en-US'}" />
      
      <light
        out="${dir.build}\setup_${release.platform}_${release.compressionlevel}.msi"
        extensions="WixUIExtension;WixNetFxExtension;WixUtilExtension"
        cultures="${cultures}"
        rebuild="true"
        suppressices="ICE03;ICE82"
        suppresspdb="true" >
      
      
          <arg line="-loc &quot;setup-${language}.wxl&quot;" />
          <arg line="-sw1101" />
      
          <arg line="-b ${dir.resources}" />
          <arg line="-b ${dir.resources.common}" />
          <arg line="-b ${dir.resources.common}\Microsoft" />
          <arg line="-b ${dir.source}" />
          <arg line="-dcl:${release.compressionlevel}" />
          <arg line="-dWixUILicenseRtf=EULA_${language}.rtf" />
          <sources>
              <include name="${dir.obj}\*.wixobj" />
          </sources>
      </light>
      

      【讨论】:

        【解决方案3】:

        我遇到过类似的情况,文件的源路径将作为命令行参数传递给构建脚本。这就是我所做的: 编辑wixproj文件,在“PropertyGroup”节点下添加如下内容:

        <Source Condition=" '$(Source)' == '' ">R:</Source>
        

        其中 R: 是从中选择源的默认目录/路径。 现在,源代码也可以在构建期间作为命令行参数传递:

        msbuild /t:Clean,Build "MyPath\MyWixProject.wixproj" /property:Source=MyConfigurablePath /p:Configuration=Release
        

        【讨论】:

        • 您只需将此属性传递给 .wixproj 文件,而不是 .wxs 文件。
        猜你喜欢
        • 2020-05-22
        • 1970-01-01
        • 1970-01-01
        • 2011-10-03
        • 1970-01-01
        • 2016-09-24
        • 1970-01-01
        • 2011-09-08
        • 1970-01-01
        相关资源
        最近更新 更多