Setting OutputName from wxi MSBUILD -Customizing Target Order

Viewed 74

I'm trying to set the <OutputName> of my .msi when using Wix in VisualStudio.

I have seen the other questions related to this, but I am approaching it a bit differently. Hoping you can all clear up some things for me.

This is my .wixproj

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" InitialTargets="EnsureWixToolsetInstalled" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
    <ProjectGuid>fa14</ProjectGuid>

    <SchemaVersion>2.0</SchemaVersion>
    <OutputName>Installer_x64_v$(Version)</OutputName>
    <OutputType>Package</OutputType>
    
    <!--<ProjectGuid>{fa1414f5-97eb-4d39-8ff6-190cd92ca99f}</ProjectGuid>-->
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    <OutputPath>bin\$(Configuration)\</OutputPath>
    <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
    <DefineConstants>Debug</DefineConstants>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    <OutputPath>bin\$(Configuration)\</OutputPath>
    <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
    <WixVariables>
    </WixVariables>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="Product.wxs" />
    <Compile Include="Files.wxs" />
    <Compile Include="UI.wxs" />
  </ItemGroup>
  <ItemGroup>
    <WixExtension Include="WixUIExtension">
      <HintPath>$(WixExtDir)\WixUIExtension.dll</HintPath>
      <Name>WixUIExtension</Name>
    </WixExtension>
  </ItemGroup>

  <Import Project="$(WixTargetsPath)" Condition=" '$(WixTargetsPath)' != '' " />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets" Condition=" '$(WixTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets') " />
  <Target Name="EnsureWixToolsetInstalled" Condition=" '$(WixTargetsImported)' != 'true' ">
    <Error Text="The WiX Toolset v3.11 (or newer) build tools must be installed to build this project. To download the WiX Toolset, see http://wixtoolset.org/releases/" />
  </Target>
  <!--
    To modify your build process, add your task inside one of the targets below and uncomment it.
    Other similar extension points exist, see Wix.targets.
    <Target Name="BeforeBuild">
    </Target>
    <Target Name="AfterBuild">
    </Target>
    -->
  <PropertyGroup>
    
  </PropertyGroup>
  <Target Name="BeforeBuild">
    
    <ReadLinesFromFile File="Configuration.wxi" >
        <Output TaskParameter="Lines" PropertyName="FileContents"/>
    </ReadLinesFromFile>
  <PropertyGroup>
    <!-- Find occurence of string ProductVersion, return everything after 'Productversion', trimming spaces and " -->
    <TrimmedWXI>$(FileContents.Substring($(FileContents.IndexOf(ProductVersion))).Replace(" ","").Replace('"',""))</TrimmedWXI>
    <!-- Find the equals sign, add 1-->
    <VersionStart>$([MSBuild]::Add($(TrimmedWXI.IndexOf(=)),1))</VersionStart>
    <!-- Find the ?-->
    <VersionEnd>$(TrimmedWXI.IndexOf(?))</VersionEnd>
    <!-- Find the length of the version-->
    <VersionLength>$([MSBuild]::Subtract($(VersionEnd),$(VersionStart)))</VersionLength>
    <!-- Find the version-->
    <Version>$(TrimmedWXI.Substring($(VersionStart),$(VersionLength)))</Version>
  </PropertyGroup>  
    <Message Importance="High" Text=" Attempting build for $(Version)" />
  </Target>
  
  <Target Name="AfterBuild">
    <Message Importance="High" Text="BuildDone" />
  </Target>
</Project>

And the configuration.wxi

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

<Include>
    <!-- Setup Configuration -->
    <?define ProductName = "Acme" ?>
    <?define ProductManufacturer = "AcmeInc." ?>
    <?define ProductVersion = "9.99" ?>
    <?define ProductUpgradeCode = "FAKEGUID" ?>  
</Include>

Now, I am setting the <Version> property appropriately, it parses the file string properly and spits it out in the message, but when it comes to the building of the .msi, it is still blank. Looks like Version gets set after the OutputName is set, and I cant overwrite or make Version set before the OutputName.

I've done some reading and messed around with the Target and build order, but I can't quite get anything to work.

It seems like the OutputName is required to be set before everything else?

Why doesn't this get overridden in the BeforeBuild target?

Is it possible to have this ReadLinesFromFile task happen before the OutputName is set? Thanks!

0 Answers
Related