2016-06-07 91 views
2

我在WiX工程文件,写这(我简化我的例子):WiX:是否可以使用变量名称作为其他变量名称的一部分?

<?define info = R172 ?> 
<?define var1="$(var.info.TargetPath)" ?> 
<?define var2="$(var.info.TargetDir)" ?> 

我想info将被预处理器扩展到这样的变体:

<?define var1="$(var.R172.TargetPath)" ?> 
<?define var2="$(var.R172.TargetDir)" ?> 

但我得到的错误:

Undefined preprocessor variable $(var.info.TargetPath) .

这种变异没有工作过:

<?define var1="$(var.$(var.info).TargetPath)" ?> 
<?define var2="$(var.$(var.info).TargetDir)" ?> 

而且我已经尝试使用foreach

<?foreach info in R172?> 
<?define var1="$(var.info.TargetPath)" ?> 
<?define var2="$(var.info.TargetDir)" ?> 
<?endforeach?> 

,但我得到了同样的问题。

可以以某种方式做类似的替换吗?

UPD

即我想用它通过foreach与引用的项目工作:

<!-- The list of the names of referensed projects --> 
<?define ACAD_VERSIONS=R172;R182;R190?> 

<?foreach ACAD in ACAD_VERSIONS?> 
    <Feature Id="Feature.$(var.ACAD)" Title="$(var.ACAD)" Level="1"> 
    <Component Id="cmp$(var.ACAD)" Guid="*" Directory="INSTALLFOLDER"> 
     <File Id="extension.$(var.ACAD).dll" Source="$(var.$(var.ACAD).TargetPath)" KeyPath="yes"/> 
    </Component> 
    </Feature> 
<?endforeach?> 

回答

1

不幸的是维克斯(3.10.2)的当前版本似乎不支持您所要求的内容。

查看WIX源代码,特别是WIX310-Debug.zip中的文件src\tools\wix\PreProcessorCore.cs,可从here下载,它看起来不像WIX支持递归名称替换。所以你不能做$(var.$(var.something))。看看功能PreprocessString(...)来确认这一点。

您或许可以使用<?undef ...?>做些什么。例如:

<?define var1="$(var.item1)" ?> 
<?include CommonFeature.wxs ?> 
. 
<?undef var1 ?> 
<?define var1="$(var.item2)" ?> 
<?include CommonFeature.wxs ?> 

查看相关的WIXToolset问题:Nested preprocessor variables

+0

但是,我想通过'foreach'循环来处理其内容时使用'var1'类似于引用项目的链接。为了清晰起见,我在示例中添加了** UPD **部分。 –

+0

谢谢。即此功能已添加到WiX 4版本中。我的理解正确吗? –

+1

不幸的是,这个功能也不在WiX版本4中。 [嵌套预处理器变量](https://github.com/wixtoolset/issues/issues/4007)的当前状态显示它是开放的并且计划用于WiX版本4。 – bradfordrg