将文件添加到Wix安装程序(如果存在) [英] Add file to Wix installer if it exists
问题描述
我正在这样尝试在我的主要wxs文件中向安装程序添加文件.
I am trying to add a file to the installer like this in my main wxs file.
<ComponentGroup Id="Files" Directory="Bin">
<?if $(var.FILE_EXISTS) = "true"?>
<Component>
<Condition>$(var.FILE_EXISTS) = "true"</Condition>
<File Source="$(var.SourceDir)/file.txt"/>
</Component>
</ComponentGroup>
我正在通过带有-d选项的Candle.exe传递FILE_EXISTS
I'm passing FILE_EXISTS through candle.exe with the -d option
但是它没有生效.它没有被添加.当我没有条件(仅File元素)时,它可以工作.有什么想法吗?
But its not taking effect. Its not getting added. It works when I don't have the conditions (just the File element). Any ideas?
推荐答案
据我了解,您所讨论的条件是构建时条件.基本上,您希望控制相关文件是否进入MSI包中.
As far as I understand, the condition you are talking about is a build-time condition. Basically, you would like to control whether the file in question gets into the MSI package.
如果正确,则一个错误是< Component>
下的< Condition>
元素.这是安装时的条件,只会影响安装文件的时间.
If that's correct, then one mistake is the <Condition>
element under <Component>
. That's install-time condition, and only influences then the file is installed.
另一个是纯语法问题.<?if?>
指令必须具有结束元素.
The other one is a pure syntax issue. The <?if?>
directive must have the closing element.
考虑到上述情况,您的代码段可能看起来像这样:
Taking the above into account, your snippet might look like this:
<ComponentGroup Id="Files" Directory="Bin">
<?if $(var.FILE_EXISTS) = "true"?>
<Component>
<File Source="$(var.SourceDir)/file.txt"/>
</Component>
<?endif?>
</ComponentGroup>
这篇关于将文件添加到Wix安装程序(如果存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!