0

After upgrading a WiX installer project (.wixproj) file to v4, the MSBuild step in the project to set the TargetName of the installer file output is no longer working.

I would like to dynamically append the assembly version of the application to be installed to the TargetName of the msi file name i.e. MyApplication.X.X.X.X.msi.

Below is a snippet of the .wixproj file in its current state (I have removed some code for the sake of brevity):

<Project InitialTargets="SetVersion;BeforeBuild;CopyLinkedContentFiles">
  <Import Project="Sdk.props" Sdk="WixToolset.Sdk" Version="4.0.0-rc.1" />
  [...]
  <Target Name="SetVersion">
    <GetAssemblyIdentity AssemblyFiles="$(SolutionDir)\bin\$(Platform)\$(Configuration)\MyApp.exe">
      <Output TaskParameter="Assemblies" ItemName="Assembly" />
    </GetAssemblyIdentity>
    <CreateProperty Value="$(SolutionName).%(Assembly.Version)">
      <Output TaskParameter="Value" PropertyName="TargetName" />
    </CreateProperty>
    <PropertyGroup>
      <DefineConstants>BuildVersion=%(Assembly.Version)</DefineConstants>
    </PropertyGroup>
  </Target>
  <Target Name="CopyLinkedContentFiles" BeforeTargets="Build">
    <Copy SourceFiles="%(Content.Identity)" DestinationFiles="%(Content.Link)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" Condition="'%(Content.Link)' != ''" />
  </Target>
  <Import Project="Sdk.targets" Sdk="WixToolset.Sdk" Version="4.0.0-rc.1" />
  [...]
</Project>

The .wixproj previous had the following code to adjust the TargetName:

<Target Name="SetVersion">
        <PropertyGroup>
            <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
            <Platform Condition=" '$(Platform)' == '' ">x64</Platform>
            <SccProjectName>SAK</SccProjectName>
            <SccProvider>SAK</SccProvider>
            <SccAuxPath>SAK</SccAuxPath>
            <SccLocalPath>SAK</SccLocalPath>
            <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\OCS.Service\</SolutionDir>
        </PropertyGroup>
        <GetAssemblyIdentity AssemblyFiles="$(SolutionDir)\bin\$(Platform)\$(Configuration)\MyApp.exe">
            <Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
        </GetAssemblyIdentity>
        <PropertyGroup>
            <DefineConstants>BuildVersion=%(AssemblyVersion.Version)</DefineConstants>
        </PropertyGroup>
        <PropertyGroup>
            <TargetName>$(SolutionName).%(AssemblyVersion.Version)</TargetName>
        </PropertyGroup>
    </Target>

The latter solution worked as expected prior to upgrading to v4, however, upon building the project and inspecting the output of the build, the change to the TargetName have not been applied.

Euan Mair
  • 1
  • 1

2 Answers2

0

I posed the question on the WiX discussion site (https://github.com/orgs/wixtoolset/discussions/7317#discussioncomment-5445882) and the answer was that WiX4 does not use TargetName et al.

I took the easy way out and set outputname to a known value. After the build I copy the installer & it's pdb using the pattern I desire, then I delete the known name.

So at the top of with wix4 project file:

    <PropertyGroup>
        <OutputName>xyzzy</OutputName>
    </PropertyGroup>

and at the bottom:

    <Import Project="Sdk.targets" Sdk="WixToolset.Sdk" Version="4.0.0-rc.4" />
    
    <Target Name="BeforeBuild">
        <!-- Get the programs assembly version from the .exe file -->
        <GetAssemblyIdentity AssemblyFiles="$(SolutionDir)SystemMonitorService.2012\$(OutputPath)SystemMonitorService.exe">
            <Output TaskParameter="Assemblies" ItemName="AsmInfo" />
        </GetAssemblyIdentity>
        <!-- Store the assembly version number in ProductVersion preprocessor variable -->
        <CreateProperty Value="$(DefineConstants);ProductVersion=%(AsmInfo.Version)">
            <Output TaskParameter="Value" PropertyName="DefineConstants" />
        </CreateProperty>
    </Target>
    
    <Target Name="AfterBuild" AfterTargets="Build">
        <!-- Name the .msi file after the solution configuration and assembly version e.g TestService-DebugAll-1.4.0.0.msi -->
        <CreateProperty Value="$(SolutionName)-$(Configuration)-%(AsmInfo.Version)">
            <Output TaskParameter="Value" PropertyName="NewOutputName" />
        </CreateProperty>
        <Copy SourceFiles="$(ProjectDir)bin\xyzzy.msi" DestinationFiles="$(ProjectDir)bin\$(NewOutputName).msi" />
        <Copy SourceFiles="$(ProjectDir)bin\xyzzy.wixpdb" DestinationFiles="$(ProjectDir)bin\$(NewOutputName).wixpdb" />
        <Delete Files="$(ProjectDir)bin\xyzzy.msi" />
        <Delete Files="$(ProjectDir)bin\xyzzy.wixpdb" />
    </Target>

which gives me my desired output of "Optimiser.2012-Debug-2.125.0.0.msi" (and the corresponding wixpdb)

0

Simply Add TargetName property in property group will suffice.

<Project Sdk="WixToolset.Sdk/4.0.0">
  <PropertyGroup>
    <SetupKitVersion>1.2.3.4</SetupKitVersion>
    <TargetName>MyProductSetup_$(SetupKitVersion)_$(Configuration)</TargetName>
  </PropertyGroup>
...
</Project>

To customize the leading name, you can add another property:

<Project Sdk="WixToolset.Sdk/4.0.0">
  <PropertyGroup>
    <SetupKitName>MyProductSetup</SetupKitName>
    <SetupKitVersion>1.2.3.4</SetupKitVersion>
    <TargetName>$(SetupKitName)_$(SetupKitVersion)_$(Configuration)</TargetName>
  </PropertyGroup>
...
</Project>

and, use the following build command:

dotnet build -p:InstallerPlatform=x64 -p:SetupKitName="NewProduct.Setup" -p:SetupKitVersion=2.2.2.2 myproduct_setup.wixproj -o publish/

ref: https://github.com/wixtoolset/wix/blob/8c757c0f67f26f21c6bcbbfb81b7ea8b91c35fe4/src/wix/WixToolset.Sdk/tools/wix.targets#L685

aDisplayName
  • 188
  • 1
  • 9