在 Rob 提供的代码的帮助下,经过更多研究,我发现如果您的安装文件夹不是标准文件夹,如何避免为每个组件提供 Guid。只需为您尝试将组件安装到的自定义目录指定 ComponentGuidGenerationSeed。指定此属性的目录不必是要安装组件的位置的直接父目录。这就是我的目录结构现在的样子:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="INETPUBFOLDER" Name="inetpub">
<Directory Id="WWWROOTFOLDER" Name="wwwroot" ComponentGuidGenerationSeed="PUT-YOUR-GUID">
<Directory Id="CONFIGLOCATION" Name="$(var.PublishLocation)" />
<Directory Id="INSTALLLOCATION" Name="$(var.PublishLocation)" >
<Directory Id="APPFOLDER" Name="bin" />
<Directory Id="MyProject.Web.Content" />
<Directory Id="CONFIGSFOLDER" Name="Configs">
<Directory Id="WEBFOLDER" Name="Web">
<Directory Id="WEBCONFIGFILES" />
</Directory>
<Directory Id="NLOGFOLDER" Name="NLog">
<Directory Id="NLOGCONFIGFILES" />
</Directory>
</Directory>
</Directory>
</Directory>
</Directory>
</Directory>
这就是我现在收获和 xml 转换的 wxs 文件的外观:
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="WEBCONFIGFILES">
<Component Id="cmp9CAF0D4A0C62775945002986D1D99926" Guid="PUT-YOUR-GUID">
<File Id="fil9C4CFE42035F1A63180142352CF441BC" KeyPath="yes" Source="$(var.WebConfigFilesDir)\Web.Dev1.config" />
</Component>
<Component Id="cmpB5117E2029EA9A7CC3AFC247EA4483AD" Guid="PUT-YOUR-GUID">
<File Id="fil0F80FEAFAD0333C3B74BB742C4FE118C" KeyPath="yes" Source="$(var.WebConfigFilesDir)\Web.Prod.config" />
</Component>
<Component Id="cmp340743041F12BBE6C7C40D4351407D08" Guid="PUT-YOUR-GUID">
<File Id="fil12F8B50F03F1BD91A579F6B6CE7195DF" KeyPath="yes" Source="$(var.WebConfigFilesDir)\Web.QA1.config" />
</Component>
</DirectoryRef>
</Fragment>
<Fragment>
<ComponentGroup Id="WebConfigFiles">
<ComponentRef Id="cmp9CAF0D4A0C62775945002986D1D99926" />
<ComponentRef Id="cmpB5117E2029EA9A7CC3AFC247EA4483AD" />
<ComponentRef Id="cmp340743041F12BBE6C7C40D4351407D08" />
</ComponentGroup>
</Fragment>
<Fragment>
<UI Id="EnvironmentComboBox">
<ComboBox Property="ENV">
<ListItem Value="Dev1" Text="Dev1" />
<ListItem Value="Prod" Text="Prod" />
<ListItem Value="QA1" Text="QA1" />
</ComboBox>
</UI>
</Fragment>
<Fragment>
<ComponentGroup Id="web.config" Directory="CONFIGLOCATION">
<Component Id="cmpWebConfigForDev1">
<Condition>ENV="Dev1"</Condition>
<File Id="CopyDev1Config" Source="$(var.WebConfigFilesDir)\Web.Dev1.config" Name="web.config" />
</Component>
<Component Id="cmpWebConfigForProd">
<Condition>ENV="Prod"</Condition>
<File Id="CopyProdConfig" Source="$(var.WebConfigFilesDir)\Web.Prod.config" Name="web.config" />
</Component>
<Component Id="cmpWebConfigForQA1">
<Condition>ENV="QA1"</Condition>
<File Id="CopyQA1Config" Source="$(var.WebConfigFilesDir)\Web.QA1.config" Name="web.config" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>
在上述文件中,收获工具仅生成前两个片段。接下来的两个片段包含 UI/ComboBox 定义和 WebconfigFiles 的 ComponentGroup,是使用 XML 转换通过从第一个片段中的 File 元素中读取信息来创建的。