我可能患有“有时会得病”,但我可以发誓,上次我涉足 WiX 时,建议有一个单独的文件来设置属性,以便以后引用(如果这些属性中的任何一个不是本意的)是静态的。基本上,在构建序列开始之前根据需要更新它们。
所以基本上,我正在尝试:
- 将属性文件加载到 WiX 项目中(完成)
- 创建一个 WiX 属性,该属性等于该属性文件中的属性之一(已阻止)
- 在根据需要安装的过程中引用该值(被阻止程序阻止,但this https://stackoverflow.com/questions/30668723/wix-toolset-how-to-set-a-property如果我被#3 阻止,一旦#2 被解除阻止,也许可以帮助我)
现在,由于尝试错误地引用变量而出现错误,我无法构建,Undefined preprocessor variable '$(var.FOO)'.
当不尝试时它构建得很好。我尝试过使用sys
and env
代替var
也。我也尝试使用[FOO]
但这似乎是按字面意思处理的,就像在检查构建日志时一样,TESTVAR
等于[FOO]
代替Bar
。我不明白为什么$(var.FOO)
没工作。我想我误解了this http://wixtoolset.org/documentation/manual/v3/overview/preprocessor.html文档。
所以我不确定我做错了什么,甚至不知道如何寻找正确的方法来做到这一点。我曾经跑过一些问题 https://stackoverflow.com/questions/12052457/wix-property-from-a-custom-action-into-a-wix-variable这可能会带来有用的答案,但它们与阻碍潜在答案的不可能性有关,例如在安装开始时尝试使用不可变的 WiX 属性作为可变属性。
它与默认模板 WiX 4 项目没什么区别,但我在下面包含了所有源文件:
变量属性
<?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>
新安装测试.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>
产品.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>