我在Visual Studio中的bundle-project上创建了几个配置,我想定义每个配置中必须包含哪些代码片段.我的目标是获得几个bootstrappers:其中一些将包括先决条件,一些不会.我尝试过类似的东西:
<PackageGroup
Id="Prerequisites">
<?if $(Configuration)='Release'?>
<ExePackage
Id="Netfx4Client"
Cache="yes"
Compressed="yes"
PerMachine="yes"
Permanent="yes"
Vital="yes"
SourceFile=".\SupportFiles\dotNetFx40_Client_x86_x64.exe"
DetectCondition="NETFRAMEWORK40CLIENT OR (VersionNT64 AND NETFRAMEWORK40CLIENTX64)"
InstallCondition="(v4.0.30319 > NETFRAMEWORK40CLIENT OR NOT NETFRAMEWORK40CLIENT) OR (VersionNT64 AND v4.0.30319 > NETFRAMEWORK40CLIENTX64 OR NOT NETFRAMEWORK40CLIENTX64)"
InstallCommand="/q /norestart /log [TempFolder]\dotnetframework4.log"/>
<?endif?>
Run Code Online (Sandbox Code Playgroud)
但当然这是不正确的..是否有可能根据任何变量管理哪些代码片段将被包含在Bundle的包中?谢谢.
是的,您首先需要将 MSBuild 属性传递给编译器的预处理器。在您的 .wixproj 中,使用该DefineConstants属性来隧道属性。Votive 提供的默认 .wixproj 默认情况下会执行此操作,Configuration但对于其他属性,它看起来像这样:
<PropertyGroup>
<DefineConstants>$(DefineConstants);MyNewVariable=$(MSBuildPropertyName)</DefineConstants>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
现在 MSBuild 属性是一个预处理器变量,您可以执行以下操作:
<?if $(var.Configuration)="Release" ?>
Stuff to conditionally compile out
<?endif?>
Run Code Online (Sandbox Code Playgroud)
基本上,上面的示例是正确的,只是您缺少var.预处理器变量名称的部分。有关预处理器语法的更多详细信息,请参阅文档。