无法将WiX属性设置为等于属性文件中的属性 [英] Unable to set a WiX Property equal to a Property from a Properties file

查看:94
本文介绍了无法将WiX属性设置为等于属性文件中的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能患上了Sometimers疾病,但上次我将脚趾浸入WiX时可能宣誓就此宣誓,建议您使用单独的文件来设置属性,以便以后引用这些属性时使用并非一成不变.基本上,在构建顺序开始之前对其进行更新.

I might be suffering from a case of Sometimers Disease, but I could have sworn the last time I dipped my toe in WiX, it was recommended to have a seperate file for setting properties to be referenced later if any of those properties aren't meant to be static. Basically, updating them before the build sequence begins as-needed.

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

So basically, I'm trying to:

  1. 将属性文件加载到WiX项目中(完成)
  2. 创建一个与该属性文件中的属性之一相等的WiX属性(已阻止)
  3. 根据需要在安装顺序中引用该值(已被阻止程序阻止,但
  1. Load the Properties file into the WiX project (done)
  2. Create a WiX Property equal to one of the properties from that Properties file (blocked)
  3. Reference that value during the sequence of installing as-needed (blocked by blocker, but this can probably help me once #2 is unblocked if I get blocked by #3)

现在,由于尝试错误地错误引用变量而导致我无法构建,Undefined preprocessor variable '$(var.FOO)'.在不尝试构建时可以正常构建.我也尝试使用sysenv而不是var.我也尝试使用[FOO],但是似乎确实可以使用它,因为在检查生成日志时,TESTVAR等于[FOO]而不是Bar.我不明白为什么$(var.FOO)无法正常工作.我想我误解了文档.

Right now, I'm not able to build due to trying to reference the variable incorrectly with the error, Undefined preprocessor variable '$(var.FOO)'. It builds fine when not trying to. I've tried using sys and env instead of var too. I also tried to use [FOO] but that seems to be treated literally, as when checking the build log, TESTVAR is equal to [FOO] instead of Bar. I don't understand why $(var.FOO) wasn't working. I guess I misunderstood this document.

因此,我不确定自己在做什么错,甚至不确定如何找到正确的方法来做到这一点.我遇到了一些问题,可能会带来有用的答案,但它们与阻碍潜在答案的可能性有关,例如一旦安装开始变得可变,就尝试使用不可变的WiX属性.

So I'm not sure what I'm doing wrong, or even how to look for the right way to do it. I've run across some questions that might have led to helpful answers, but they had to do with impossibilities that stunted potential answers, like trying to use the immutable WiX properties once installation starts as mutable.

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

It's not much more than a default template WiX 4 project, but I've included all my source files below:

<?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)之外,还必须在.wixproj中的<DefineConstants>下分配Candle预处理程序变量,以便它们可以在您的wix项目中使用. 这应该可以解决您的Undefined preprocessor variable '$(var.FOO)'

Besides setting the msbuild properties (you vars.properties), you have to assign Candle preprocessor variables in your .wixproj, under <DefineConstants> as well so that they can be used in you wix projects. This should fix your 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>

这篇关于无法将WiX属性设置为等于属性文件中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆