无法将属性文件中的 WiX 属性 设置为等于 属性

Unable to set a WiX Property equal to a Property from a Properties file

我可能患有 Sometimers 病,但我可以发誓上次我在 WiX 中尝试时,建议使用一个单独的文件来设置属性,如果有的话,以后可以参考属性并不意味着是静态的。基本上,根据需要在构建序列开始之前更新它们。

所以基本上,我正在尝试:

  1. 将属性文件加载到 WiX 项目中(完成)
  2. 创建一个 WiX 属性 等于该属性文件中的一个属性(已阻止)
  3. 根据需要在安装序列中引用该值(被阻止程序阻止,但如果我被#3 阻止, 可能会帮助我一旦#2 被解除阻止)

现在,由于尝试错误地引用变量并出现错误,我无法构建,Undefined preprocessor variable '$(var.FOO)'.它在不尝试时构建良好。我也尝试过使用 sysenv 而不是 var。我也尝试使用 [FOO],但这似乎是字面意思,因为在检查构建日志时,TESTVAR 等于 [FOO] 而不是 Bar。我不明白为什么 $(var.FOO) 不起作用。我想我误解了 this 文档。

所以我不确定我做错了什么,甚至不知道如何寻找正确的方法。我在 some questions 中 运行 可能会得到有用的答案,但它们与阻碍潜在答案的可能性有关,比如在安装开始后尝试使用不可变的 WiX 属性作为可变的。

它只不过是一个默认模板 WiX 4 项目,但我在下面包含了我的所有源文件:

vars.properties

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
  <PropertyGroup>
    <FOO>Bar</FOO>
  </PropertyGroup>
</Project>

NewSetupTest.wixproj

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" InitialTargets="EnsureWixToolsetInstalled" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="vars.properties" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
    <ProductVersion>3.9</ProductVersion>
    <ProjectGuid>75fa9a4b-ddfe-44a6-8b03-2f26612b3339</ProjectGuid>
    <SchemaVersion>2.0</SchemaVersion>
    <OutputName>NewSetupTest</OutputName>
    <OutputType>Package</OutputType>
    <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\WiX Toolset\v4\wix.targets</WixTargetsPath>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    <OutputPath>bin$(Configuration)\</OutputPath>
    <IntermediateOutputPath>obj$(Configuration)\</IntermediateOutputPath>
    <DefineConstants>Debug</DefineConstants>
    <VerboseOutput>False</VerboseOutput>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    <OutputPath>bin$(Configuration)\</OutputPath>
    <IntermediateOutputPath>obj$(Configuration)\</IntermediateOutputPath>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="Product.wxs" />
  </ItemGroup>
  <ItemGroup>
    <Content Include="vars.properties" />
  </ItemGroup>
  <Import Project="$(WixTargetsPath)" Condition=" Exists('$(WixTargetsPath)') " />
  <Target Name="EnsureWixToolsetInstalled" Condition=" !Exists('$(WixTargetsPath)') ">
    <Error Text="The WiX Toolset v4 build tools must be installed to build this project. To download the WiX Toolset v4, 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>
    -->
</Project>

Product.wxs

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
    <Product Id="7E5959E4-664D-4D24-9B45-BA2697CA303B"
            Name="NewSetupTest"
            Language="1033"
            Version="1.0.0.3"
            Manufacturer="ACME"
            UpgradeCode="A38ABDBE-2D5F-450D-97EE-19C5A018101B">
        <Package InstallerVersion="200"
              Compressed="yes"
              InstallScope="perMachine" Platform="x64" />

        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." AllowSameVersionUpgrades="yes"/>
        <MediaTemplate />

        <Feature Id="ProductFeature"
              Title="NewSetupTest"
              Level="1">
            <ComponentGroupRef Id="ProductComponents" />
        </Feature>
    </Product>

    <Fragment>
        <Directory Id="TARGETDIR"
                Name="SourceDir">
            <Directory Id="ProgramFilesFolder64">
                <Directory Id="INSTALLFOLDER"
                    Name="NewSetupTest" />
            </Directory>
        </Directory>
    </Fragment>

    <Fragment>
    <Property Id="TESTVAR" Secure="yes" Value="$(var.FOO)" />
        <ComponentGroup Id="ProductComponents"
                      Directory="INSTALLFOLDER">
            <!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
            <!-- <Component Id="ProductComponent"> -->
                <!-- TODO: Insert files, registry keys, and other resources here. -->
            <!-- </Component> -->
        </ComponentGroup>
    <InstallExecuteSequence>
      <ScheduleReboot After="InstallFinalize">NOT (TESTVAR = "Bar")</ScheduleReboot>
    </InstallExecuteSequence>
    </Fragment>
</Wix>

除了设置 msbuild 属性(您 vars.properties)之外,您还必须在 <DefineConstants> 下的 .wixproj 中分配 Candle 预处理器变量,以便它们可以在您的 wix 项目中使用。 这应该可以修复您的 Undefined preprocessor variable '$(var.FOO)'

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    <OutputPath>bin$(Configuration)\</OutputPath>
    <IntermediateOutputPath>obj$(Configuration)\</IntermediateOutputPath>
    <DefineConstants>Debug;FOO=$(FOO)</DefineConstants>
    <VerboseOutput>False</VerboseOutput>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    <OutputPath>bin$(Configuration)\</OutputPath>
    <IntermediateOutputPath>obj$(Configuration)\</IntermediateOutputPath>
    <DefineConstants>FOO=$(FOO)</DefineConstants>
</PropertyGroup>