Невозможно установить свойство WiX равным свойству из файла свойств

Я мог страдать от случая Sometimers Disease, но я мог бы поклясться в последний раз, когда я опустил носок в WiX, было рекомендовано иметь отдельный файл для настройки свойств, на которые можно ссылаться позже, если какое-либо из этих свойств не предназначено быть статичным. В основном, их обновление до начала последовательности сборки по мере необходимости.

В общем, я пытаюсь:

  1. Загрузите файл свойств в проект WiX (готово)
  2. Создайте свойство WiX, равное одному из свойств этого файла свойств (заблокировано)
  3. Обращайтесь к этому значению во время последовательности установки по мере необходимости (блокируется блокировщиком, но это, вероятно, может помочь мне, если #2 разблокируется, если меня заблокирует #3)

Сейчас я не могу построить из-за попытки неправильно ссылаться на переменную с ошибкой, Undefined preprocessor variable '$(var.FOO)'. Он прекрасно строит, когда не пытается. Я пытался использовать sys а также env вместо var тоже. Я также пытался использовать [FOO] но это, кажется, трактуется буквально, как при проверке журнала сборки, TESTVAR равно [FOO] вместо Bar, Я не понимаю почему $(var.FOO) не работал Думаю, я неправильно понял этот документ.

Так что я не уверен, что я делаю не так или даже как искать правильный способ сделать это. Я столкнулся с некоторыми вопросами, которые могли привести к полезным ответам, но они были связаны с невозможностью, которая задерживала потенциальные ответы, например, пытаясь использовать неизменяемые свойства 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>

1 ответ

Решение

Помимо установки свойств msbuild (вы vars.properties), вы должны назначить переменные препроцессора Candle в вашем.wixproj, в разделе <DefineConstants> а также, чтобы они могли быть использованы в ваших проектах 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>
Другие вопросы по тегам