WiX 如何定义多个 HarvestPaths

huangapple go评论45阅读模式
英文:

WiX how to define multiple HarvestPaths

问题

我试图使用 WiX 构建一个安装程序。我的软件为不同版本提供更新(V23V22V21 等)。我使用 Heat 动态生成所需库(包括自己的)的列表。我希望我的安装程序能够:

  1. 是一个单一的安装程序,将所有版本的内容安装到一个文件夹中(每个版本在其各自的子文件夹中)。这是因为单个用户可能同时使用我们软件的不同版本。
  2. 在创建安装程序时,安装程序应正确获取每年的构建。

我能想到的最简单的方法是有三个不同的收集路径,每个路径对应一个 Heat 生成的 DLL 列表。然而,wix/heat 不允许我将收集路径命名为除 HarvestPath 以外的任何名称,因此以下内容不起作用。它仍然突出显示我想要实现的目标,这就是我在这里发布它的原因。我应该如何实现我在这里尝试做的事情?

英文:

I'm trying to build an installer using WiX. My software provides updates for different versions (V23, V22, V21, and so on). I'm using Heat to generate the list of required libraries (including my own) dynamically.
I'd like my Installer to:

  1. Be a single installer that installs the content for all releases in a single folder (with each version in their respective subfolders). This is because a single user might use different versions of our software at the same time.
  2. The installer should correctly grab the builds of each year when creating the installer.

The easiest way I could think of doing this would be to have three different harvest paths, one for each heat generated list of DLLs. However, wix/heat doesn't allow me to name the harvestpath anything other than HarvestPath, so the following doesn't work. It still highlights what I want to achieve, which is why I'm posting it here nonetheless.
How would I achieve what I'm trying to do here?

Installer.wixproj

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    <OutputPath>bin$(Configuration)\</OutputPath>
    <IntermediateOutputPath>obj$(Configuration)\</IntermediateOutputPath>
    <DefineConstants>HarvestPath23=..\MySoftware\bin\REL23\</DefineConstants>
    <DefineConstants>HarvestPath22=..\MySoftware\bin\REL22\</DefineConstants>
    <DefineConstants>HarvestPath21=..\MySoftware\bin\REL21\</DefineConstants>
    <Cultures>en-US</Cultures>
</PropertyGroup>

<ItemGroup>
    <Compile Include="Product.wxs"/>
    <!-- This is the Heat created one for 23 -->
    <Compile Include="HeatGeneratedFileList23.wxs"/>
    <!-- This is the Heat created one for 22 -->
    <Compile Include="HeatGeneratedFileList22.wxs"/>
    <!-- This is the Heat created one for 21 -->
    <Compile Include="HeatGeneratedFileList21.wxs"/>

</ItemGroup>

<Target Name="BeforeBuild">
    <HeatDirectory Directory="..\MySoftware\bin\REL23\" PreprocessorVariable="var.HarvestPath23" OutputFile="HeatGeneratedFileList23.wxs" ComponentGroupName="HeatGenerated23" RunAsSeparateProcess="$(RunWixToolsOutOfProc)" DirectoryRefId="INSTALLFOLDER23" AutogenerateGuids="true" ToolPath="$(WixToolPath)" SuppressFragments="true" SuppressRegistry="true" SuppressRootDirectory="true"/>
    <HeatDirectory Directory="..\MySoftware\bin\REL22\" PreprocessorVariable="var.HarvestPath22" OutputFile="HeatGeneratedFileList22.wxs" ComponentGroupName="HeatGenerated22" RunAsSeparateProcess="$(RunWixToolsOutOfProc)" DirectoryRefId="INSTALLFOLDER22" AutogenerateGuids="true" ToolPath="$(WixToolPath)" SuppressFragments="true" SuppressRegistry="true" SuppressRootDirectory="true"/>
    <HeatDirectory Directory="..\MySoftware\bin\REL21\" PreprocessorVariable="var.HarvestPath21" OutputFile="HeatGeneratedFileList21.wxs" ComponentGroupName="HeatGenerated21" RunAsSeparateProcess="$(RunWixToolsOutOfProc)" DirectoryRefId="INSTALLFOLDER21" AutogenerateGuids="true" ToolPath="$(WixToolPath)" SuppressFragments="true" SuppressRegistry="true" SuppressRootDirectory="true"/>
</Target>

Product.wxs

    <Feature Id="ProductFeature23" Title="My super software 2023" Level="1"
             ConfigurableDirectory="INSTALLFOLDER23">
        <ComponentGroupRef Id="HeatGenerated23"/>
        <ComponentGroupRef Id="ProductContents"/>
    </Feature>
    <Feature Id="ProductFeature22" Title="My super software 2022" Level="1"
             ConfigurableDirectory="INSTALLFOLDER22">
        <ComponentGroupRef Id="HeatGenerated22"/>
    </Feature>
    <Feature Id="ProductFeature21" Title="My super software 2021" Level="1"
             ConfigurableDirectory="INSTALLFOLDER21">
        <ComponentGroupRef Id="HeatGenerated21"/>
    </Feature>
</Product>

<Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="CommonAppDataFolder" Name="MyAppDataFolder">
            <Directory Id="DIR_FOO" Name="FOO">
                <Directory Id="DIR_Contents" Name="Contents">
                    <Directory Id="INSTALLFOLDER23" Name="2023"/>
                    <Directory Id="INSTALLFOLDER22" Name="2022"/>
                    <Directory Id="INSTALLFOLDER21" Name="2021"/>
                </Directory>
            </Directory>
        </Directory>
    </Directory>
</Fragment>

答案1

得分: 1

以下是翻译好的代码部分:

在 MSBuild 片段中,以下内容:

<PropertyGroup>
  <DefineConstants>HarvestPath23=..\MySoftware\bin\REL23</DefineConstants>
  <DefineConstants>HarvestPath22=..\MySoftware\bin\REL22</DefineConstants>
  <DefineConstants>HarvestPath21=..\MySoftware\bin\REL21</DefineConstants>
</PropertyGroup>

在 C#/C/C++ 片段中本质上相同:

int DefineConstants;
DefineConstants = 1;
DefineConstants = 2;
DefineConstants = 3;

在这两种情况下,DefineConstants 的值都被设置为最后一次赋值。有两种方法可以在 MSBuild 语法中修复这个问题,一种是将它们合并为一个赋值:

<PropertyGroup>
  <DefineConstants>
    HarvestPath23=..\MySoftware\bin\REL23;
    HarvestPath22=..\MySoftware\bin\REL22;
    HarvestPath21=..\MySoftware\bin\REL21
  </DefineConstants>
</PropertyGroup>

(注意:空白字符将被忽略)

另一种方法是在每一行上连接变量名,如下:

<PropertyGroup>
  <DefineConstants>$(DefineConstants);HarvestPath23=..\MySoftware\bin\REL23</DefineConstants>
  <DefineConstants>$(DefineConstants);HarvestPath22=..\MySoftware\bin\REL22</DefineConstants>
  <DefineConstants>$(DefineConstants);HarvestPath21=..\MySoftware\bin\REL21</DefineConstants>
</PropertyGroup>

注意:这与 WiX Toolset 没有任何关系,而与 MSBuild 语法有关。

英文:

The OP answered the question but here is why it works. The following in MSBuild snippet:

&lt;PropertyGroup&gt;
  &lt;DefineConstants&gt;HarvestPath23=..\MySoftware\bin\REL23\&lt;/DefineConstants&gt;
  &lt;DefineConstants&gt;HarvestPath22=..\MySoftware\bin\REL22\&lt;/DefineConstants&gt;
  &lt;DefineConstants&gt;HarvestPath21=..\MySoftware\bin\REL21\&lt;/DefineConstants&gt;
&lt;/PropertyGroup&gt;

is essentially the same in the C#/C/C++ snippet:

int DefineConstants;
DefineConstants = 1;
DefineConstants = 2;
DefineConstants = 3;

In both cases, the DefineConstants value gets set to the last assignment. There are two ways to fix this in MSBuild syntax, combine into one assignment

&lt;PropertyGroup&gt;
  &lt;DefineConstants&gt;
    HarvestPath23=..\MySoftware\bin\REL23\;
    HarvestPath22=..\MySoftware\bin\REL22\&#39;
    HarvestPath21=..\MySoftware\bin\REL21\
  &lt;/DefineConstants&gt;
&lt;/PropertyGroup&gt;

(note: the white space gets ignored)

Or, concatenate the variable name on each line like:

&lt;PropertyGroup&gt;
  &lt;DefineConstants&gt;$(DefineConstants);HarvestPath23=..\MySoftware\bin\REL23\&lt;/DefineConstants&gt;
  &lt;DefineConstants&gt;$(DefineConstants);HarvestPath22=..\MySoftware\bin\REL22\&lt;/DefineConstants&gt;
  &lt;DefineConstants&gt;$(DefineConstants);HarvestPath21=..\MySoftware\bin\REL21\&lt;/DefineConstants&gt;
&lt;/PropertyGroup&gt;

Note: This really has nothing to do with the WiX Toolset and everything to do with MSBuild syntax.

答案2

得分: 0

你可以使用以下内容来替代原文中的代码部分:

<DefineConstants>HarvestPath23=..\MySoftware\bin\REL23\;HarvestPath22=..\MySoftware\bin\REL22\;HarvestPath21=..\MySoftware\bin\REL21\</DefineConstants>

希望这有所帮助!

英文:

Ok I actually managed to do exactly what I wanted by just defining all three HarvestPaths in one DefineConstants context instead of three separate ones.
So in the code sample above, instead of this:

&lt;DefineConstants&gt;HarvestPath23=..\MySoftware\bin\REL23\&lt;/DefineConstants&gt;
&lt;DefineConstants&gt;HarvestPath22=..\MySoftware\bin\REL22\&lt;/DefineConstants&gt;
&lt;DefineConstants&gt;HarvestPath21=..\MySoftware\bin\REL21\&lt;/DefineConstants&gt;

use this

&lt;DefineConstants&gt;HarvestPath23=..\MySoftware\bin\REL23\;HarvestPath22=..\MySoftware\bin\REL22\;HarvestPath21=..\MySoftware\bin\REL21\&lt;/DefineConstants&gt;

and all the rest works fine!

huangapple
  • 本文由 发表于 2023年3月21日 00:34:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75792945.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定