Samselvaprabu
Samselvaprabu

Reputation: 18147

How to pass parameter to Wix patch?

We are creating patch using Wix. It is given below

<Family DiskId="5000"
        MediaSrcProp="Sample"
        Name="Sample"
        SequenceStart="5000">
      <UpgradeImage SourceFile="Z:\MyViewName\Latest_UnCompressed\EmailTrans.msi" Id="Latest">
        <TargetImage SourceFile="Z:\MyViewName\Prev_Uncompressed\EmailTrans.msi" Order="2" Id="Previous" IgnoreMissingFiles="no"/>
      </UpgradeImage>
    </Family>

I do not want to use <UpgradeImage SourceFile="Z:\MyViewName , Because this may change often. I am using Msbuild target like below to build it

 <Target Name="CreateUncompressFolder">

    <RemoveDir Condition="Exists('$(OldUncompressedMsiPath)')" Directories="$(OldUncompressedMsiPath)" />
    <MakeDir Condition="!Exists('$(OldUncompressedMsiPath)')" Directories="$(OldUncompressedMsiPath)" />

    <RemoveDir Condition="Exists('$(NewUncompressedMsiPath)')" Directories="$(NewUncompressedMsiPath)" />
    <MakeDir Condition="!Exists('$(NewUncompressedMsiPath)')" Directories="$(NewUncompressedMsiPath)" />

  </Target>


  <Target Name="UnCompressMsi" DependsOnTargets="CreateUncompressFolder">

    <Exec Command="msiexec.exe /a &quot;$(NewMsiPath)&quot; /qb TARGETDIR=&quot;$(NewUncompressedMsiPath)&quot;"/>

    <Exec Command="msiexec.exe /a &quot;$(OldMsiPath)&quot; /qb TARGETDIR=&quot;$(OldUncompressedMsiPath)&quot;"/>

  </Target>

  <Target Name="BuildMsp">


    <Exec Command="candle.exe &quot;$(PatchWxsName)&quot;"/>

    <Exec Command="light.exe &quot;$(WixObj)&quot; -out &quot;$(PCPName)&quot;"/>

    <Exec Command="msimsp.exe -s &quot;$(PCPName)&quot; -p &quot;$(MspName)&quot; -l &quot;Patch.log&quot; "/>

  </Target>

Is it possible to pass Z:\MyViewName as parameter via Msbuild ?

Upvotes: 0

Views: 1153

Answers (1)

Hasani Blackwell
Hasani Blackwell

Reputation: 2056

You need to use the DefineConstants and have msbuild pass in parameters to your .wixproj as parameters. In Automating WiX with MSBuild, you'll see he's passing in PRODUCTVERSION as a MSBUILD parameter to the wixproj and he can then reference the value of PRODUCTVERSION using $(var.PRODUCTVERSION) in his WXS file. Another approach I've seen done, which is pretty much the same in the link i mentioned is to instead add the XML element DefineConstants as a property to the PropertyGroup in the .wixproj file instead of creating the property on the fly in the BeforeBuild target.

E.x.:


<Project>
<PropertyGroup>
<Configuration/>
<Platform/>
<DefineConstants>
BuildVersion=$(ProductVersion);
WixVarName=$(MSBuildPropertyName);
WixVarName1=$(MSBuildPropertyName1);
WixVarName2=$(MSBuildPropertyName2);
</DefineConstants>
<OutputPath/>
<OutputName/>

Upvotes: 1

Related Questions