Include MajorVersion etc in filename (OutputName)

2019-01-22 13:03发布

In my Defines.wxi I have:

<?define MajorVersion="1" ?>
<?define MinorVersion="08" ?>
<?define BuildVersion="11" ?>

In my MyProject.Setup.wixproj I have:

<OutputName>MyProject</OutputName>
<OutputType>Package</OutputType>

Is it possible to include the version variables in the filename somehow, so that my file can be named MyProject.1.08.11.msi?

This didn't work (no such variable is defined):

<OutputName>MyProject-$(MajorVersion)</OutputName>
<OutputType>Package</OutputType>

This didn't work (no such variable is defined):

<Target Name="AfterBuild" Condition="'$(Configuration)' == 'Release'">
    <Copy SourceFiles="$(OutputPath)$(OutputName).msi" DestinationFiles="C:\$(OutputName)-$(MajorVersion).msi" />
</Target>

It seems very clear to me that $(MajorVersion) is not the correct way of fetching the definition from the Defines.wxi file. What is?


Update

I tried to put this in MyProject.Setup.wixproj:

<InstallerMajorVersion>7</InstallerMajorVersion>
<InstallerMinorVersion>7</InstallerMinorVersion>
<InstallerBuildNumber>7</InstallerBuildNumber>

...

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    <OutputPath>bin\$(Configuration)\</OutputPath>
    <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
    <DefineConstants>PrebuildPath=..\..\obj\prebuild\web\;InstallerMajorVersion=$(InstallerMajorVersion);InstallerMinorVersion=$(InstallerMinorVersion);InstallerBuildNumber=$(InstallerBuildNumber)</DefineConstants>
</PropertyGroup>

And this in Defines.wxi:

<?define MajorVersion="$(var.InstallerMajorVersion)" ?>
<?define MinorVersion="$(var.InstallerMinorVersion)" ?>
<?define BuildVersion="$(var.InstallerBuildNumber)" ?>
<?define Revision="0" ?>
<?define VersionNumber="$(var.InstallerMajorVersion).$(var.InstallerMinorVersion).$(var.InstallerBuildNumber)" ?>

Didn't work either. Got these error messages:

  • The Product/@Version attribute's value, '..', is not a valid version. Legal version values should look like 'x.x.x.x' where x is an integer from 0 to 65534.
  • The Product/@Version attribute was not found; it is required.

7条回答
叛逆
2楼-- · 2019-01-22 13:51

This is a full example of a wixproj file where you can set a version number in the UI and use that to modify the output msi file name.

In Visual Studio (e.g. 2015):

  • define a version number in "Define preprocessor variables" in the project properties window. I've entered VersionNumber=1.14 for this example;
  • unload your project in the solution explorer;
  • right click your project in the solution explorer and select edit yourproject.wixproj file;
  • add code in the Target Name="BeforeBuild" element as shown below.

    <?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>
        <ProductVersion>3.10</ProductVersion>
        <ProjectGuid>PROJECT-GUID</ProjectGuid>
        <SchemaVersion>2.0</SchemaVersion>
        <OutputName>my project</OutputName>
        <OutputType>Package</OutputType>
      </PropertyGroup>
      <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
        <OutputPath>bin\$(Configuration)\</OutputPath>
        <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
        <!-- These constants can be set in the UI -->
        <DefineConstants>VersionNumber=1.14</DefineConstants>
      </PropertyGroup>
      <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
        <OutputPath>bin\$(Configuration)\</OutputPath>
        <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
        <DefineConstants>VersionNumber=1.14</DefineConstants>
      </PropertyGroup>
      <ItemGroup>
        <Compile Include="Product.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="BeforeBuild">
        <!-- This extracts the version number from a setting in the UI -->
        <!-- This method comes from: geekswithblogs.net/alexhildyard/archive/2013/03/09/passing-data-between-msbuild-and-wix.aspx -->
        <ItemGroup>
          <DefineConstantsKVPairs Include="$(DefineConstants)" />
        </ItemGroup>
        <!-- Evaluate each key/value pair with task batching, then make a conditional assignment -->
        <PropertyGroup>
          <VersionNumber Condition="$([System.String]::new('%(DefineConstantsKVPairs.Identity)').Contains('VersionNumber='))">$([System.String]::new('%(DefineConstantsKVPairs.Identity)').Split('=')[1])</VersionNumber>
        </PropertyGroup>
    
        <CreateProperty Value="$(OutputName)-$(VersionNumber)">
          <Output TaskParameter="Value" PropertyName="TargetName" />
        </CreateProperty>
        <CreateProperty Value="$(TargetName)$(TargetExt)">
          <Output TaskParameter="Value" PropertyName="TargetFileName" />
        </CreateProperty>
        <CreateProperty Value="$(TargetDir)$(TargetFileName)">
          <Output TaskParameter="Value" PropertyName="TargetPath" />
        </CreateProperty>
      </Target>
    </Project>
    
查看更多
登录 后发表回答