Passing build parameters to .wxs file to dynamically build wix installers

后端 未结 3 2138
臣服心动
臣服心动 2021-02-13 21:52

I am a student developer and I have built several installers for the company I am working with now. So I am fairly familiar with WIX. We recently decided to have a Build server

相关标签:
3条回答
  • 2021-02-13 22:03

    I had a similar situation where the source path of the files was to be passed as a command line argument to the build script. This is what I did: Edited the wixproj file and added the following content under the "PropertyGroup" node:

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

    where R: is the default directory/path from where to pick the source. Now, the source can also be passed as a command line argument during build:

    msbuild /t:Clean,Build "MyPath\MyWixProject.wixproj" /property:Source=MyConfigurablePath /p:Configuration=Release
    
    0 讨论(0)
  • 2021-02-13 22:15

    As already answered, you need to pass the variables into WiX. We use Nant instead of MSBuild, but the concept remains the same.

    Here's a Nant example passing in half a dozen variables to candle (it's not the cleanest example, but is lifted verbatim from a project I worked on)

    <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>
    
    0 讨论(0)
  • 2021-02-13 22:21

    The reason it's not working for you is that you are setting msbuild properties on the command line, which are not getting passed through as wix variables. MSBuild properties and wix variables are two different concepts.

    One way to fix this is to ignore the concept of msbuild properties and use environment variables to pass values directly to candle.exe. You can use environment variables in your wxs file like this:

    $(env.SpecialPath)
    

    You can then launch your setup build from a batch file which prepares the necessary environment variables like this:

    @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
    

    Alternatively, if you prefer to pass parameters via msbuild properties, you should first take a look at the msbuild candle task documentation. It shows you can set values in your wixproj file like this:

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

    This still requires you to hardcode values in the wixproj file though. If you want to pass the values as msbuild properties on the command line, then you should probably do something like this:

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

    and then pass /p:value1=foo /p:value2=bar on the command line, or define these msbuild properties elsewhere.

    0 讨论(0)
提交回复
热议问题