如何在Wix安装中仅部署SourceDir文件而不创建子目录?
WIX安装配置问题:按环境变量选文件且不创建子目录
场景说明
我有两个源文件夹hml和prod,包含同名文件:
source-files\hml\prop.txtsource-files\prod\prop.txt
需根据环境变量选择安装hml或prod文件夹中的内容。
Heat.exe生成的WXS文件
<?xml version="1.0" encoding="utf-8"?> <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> <Fragment> <DirectoryRef Id="DRTest"> <Directory Id="dir955DBF4D2285F2E21C32C59406B537CE" Name="hml" /> <Directory Id="dirD719650CC1B2842144EDDEE82C74F4F8" Name="prod" /> </DirectoryRef> </Fragment> <Fragment> <ComponentGroup Id="CGTest"> <Component Id="cmpEFE4E22AB34DA3EB5B946F5BB2C9607F" Directory="dir955DBF4D2285F2E21C32C59406B537CE" Guid="{34608A80-DED6-4CE1-B270-D74A4EC672D1}"> <Condition><![CDATA[ENVIRONMENT="H"]]></Condition> <File Id="fil6762F479FB1087BFED02566F581D8DC3" KeyPath="yes" Source="SourceDir\hml\prop.txt" /> </Component> <Component Id="cmpC8F54E05FD0D1FEB5D23E8E250BDC3CC" Directory="dirD719650CC1B2842144EDDEE82C74F4F8" Guid="{3A60E929-C1CC-4317-9486-05DB5D03EA36}"> <Condition><![CDATA[ENVIRONMENT="P"]]></Condition> <File Id="fil81946DAEA8CB358FB28F167A00902CAC" KeyPath="yes" Source="SourceDir\prod\prop.txt" /> </Component> <Component Id="cmp892267248C5EB88377233E323E9CBC61" Directory="dirD719650CC1B2842144EDDEE82C74F4F8" Guid="{3FD22301-A44E-4BB6-AD7C-A91F0AF9E4D7}"> <Condition><![CDATA[ENVIRONMENT="P"]]></Condition> <File Id="fil83C6A493C601DC451F7D48B8005B7489" KeyPath="yes" Source="SourceDir\prod\prop2.txt" /> </Component> </ComponentGroup> <Property Id="ENVIRONMENT"> <RegistrySearch Id="ENVIRONMENT" Root="HKCU" Key="System\CurrentControlSet\Policies" Name="ENVIRONMENT" Type="raw" /> </Property> </Fragment> </Wix>
带安装程序属性的WXS文件
<?xml version="1.0" encoding="utf-8"?> <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> <Product Id="a09e1fd5-abb0-4a1e-ba61-aa087b8691e7" Name="NameTest" Version="1.0.0" Manufacturer="Manufacturer" UpgradeCode="a09e1fd5-abb0-4a1e-ba61-aa087b8691e6" Language="1033"> <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" Manufacturer="Manufacturer" /> <Media Id="1" Cabinet="installer.cab" EmbedCab="yes"/> <MajorUpgrade DowngradeErrorMessage="A newer version is already installed"/> <Feature Id="ProductFeature" Title="TitleTeste" Level="1"> <ComponentGroupRef Id="CGTest"/> </Feature> </Product> <Fragment> <SetDirectory Id="INSTALLFOLDER" Value="C:\test"/> <Directory Id="TARGETDIR" Name="SourceDir"> <Directory Id="INSTALLFOLDER" > <Directory Id="DRTest"/> </Directory> </Directory> </Fragment> </Wix>
XSLT转换文件
<xsl:template match='//wix:Wix/wix:Fragment/wix:ComponentGroup/wix:Component[wix:File[@Source and (contains(@Source, "hml"))]]'> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:element name="Condition" namespace="http://schemas.microsoft.com/wix/2006/wi"> <xsl:text disable-output-escaping="yes"><![CDATA[ENVIRONMENT="H"</xsl:text> <xsl:text disable-output-escaping="yes">]]></xsl:text> </xsl:element> <xsl:apply-templates select="node()"/> </xsl:copy> </xsl:template> <xsl:template match='//wix:Wix/wix:Fragment/wix:ComponentGroup/wix:Component[wix:File[@Source and (contains(@Source, "prod"))]]'> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:element name="Condition" namespace="http://schemas.microsoft.com/wix/2006/wi"> <xsl:text disable-output-escaping="yes"><![CDATA[ENVIRONMENT="P"</xsl:text> <xsl:text disable-output-escaping="yes">]]></xsl:text> </xsl:element> <xsl:apply-templates select="node()"/> </xsl:copy> </xsl:template>
当前问题与期望
运行安装程序后,生成的目标文件夹结构为:c:\test\hml\prop.txt
但期望的结构是:c:\test\prop.txt
需要实现仅安装对应环境的文件,不在目标目录下创建hml或prod子目录。
内容的提问来源于stack exchange,提问作者Jonathas Garcia
相关产品推荐
相关产品推荐

