19

我正在使用 Wix 为网站创建安装。

添加字体时,WiX 会选择 .ttf 扩展名并要求您将其安装到本地字体文件夹(使用 Directory Id="FontsFolder" 和 TrueType="yes" 时)。如果您删除这些属性,它就会崩溃。

有没有办法让 WiX 将字体安装到自定义文件夹 (../Content/fonts/) 而不会抱怨?

编辑:

   <Directory Id="dirFontsFolder" Name="fonts">
       <Component Id="cfont.ttf" Guid="BDEBACC8-D057-4406-87B9-B310BA6DFE27">
           <File Id="font.ttf" Source="$(var.SrcWebsite)\Content\fonts\font.ttf" KeyPath="yes" />
       </Component>
   </Directory>

使用上面的代码,我得到了错误:

错误 LGHT1076:ICE60:文件 font.ttf 不是字体,它的版本不是伴随文件参考。它应该具有在语言列中指定的语言。

4

4 回答 4

13

几个月后提出问题后,我们设法找到了问题:

KeyPath 解决方案是答案的一半(参见 Alex 的答案)。如果不使用 WiX 中的 KeyPath 属性,以下解决方案将不起作用。

另一部分是 WiX 在打包 MSI 时通过链接器 (light.exe) 运行的内部一致性评估器 (ICE)。ICE 规则 ICE07,检查文件的内容,如果确定文件是字体,将强制文件在 Windows/Fonts 中。

要阻止这种情况发生,您需要在 light.exe 运行时禁用此规则。为此,您需要在 light.exe 之后添加 -sice: 参数。对于我们的示例,它将是:

light.exe -sice:ICE07

您可以通过添加更多 -sice 参数来禁用多个规则。

于 2013-03-08T12:52:47.800 回答
5

您可以使用 VS 实现相同的目标:

右键单击设置项目,单击属性。

选择工具设置选项卡。

在 ICE 验证部分,您可以禁止所有警告,或特定的一个 ICEXX,在这种情况下

[冰60]

或者

在同一个 TAB(工具设置)上,您可以向编译器或链接器添加其他参数。所以,在链接器部分只需添加

[-sice:ICE60]

于 2014-10-03T15:46:20.600 回答
5

对于引导 glyphicons_halflings.ttf字体的特定情况,该字体通过设计放入网站的字体文件夹,此解决方案在不抑制 ICE07 警告的情况下工作:

因为您还将同时安装匹配的 woff、eot 和 svg webfonts,您可以指定 TTF 文件有一个伴随文件而不是 TrueType 字体。

如果您天真地创建一个 WiX 片段以将 Halflings 字体文件添加到您的站点字体文件夹,如下所示:(根据需要替换部分 GUID)

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <DirectoryRef Id="WebsiteFontsDir">
            <Component Id="CMP_WebsiteFonts" Guid="{********-482C-4924-B06E-9FAC34F89D1D}" KeyPath="yes">
                <File Id="glyphicons_halflings_regular.eot" Source="$(var.ViewerModule.TargetDir)Police\fonts\glyphicons-halflings-regular.eot" />
                <File Id="glyphicons_halflings_regular.svg" Source="$(var.ViewerModule.TargetDir)Police\fonts\glyphicons-halflings-regular.svg" />
                <File Id="glyphicons_halflings_regular.woff" Source="$(var.ViewerModule.TargetDir)Police\fonts\glyphicons-halflings-regular.woff" />
            </Component>
            <Component Id="CMP_WebsiteFonts2" Guid="{********-BFFE-441D-B8F4-156DD596B09F}" KeyPath="yes">
                <File Id="glyphicons_halflings_regular.ttf" Source="$(var.ViewerModule.TargetDir)Police\fonts\glyphicons-halflings-regular.ttf" DefaultVersion="1.001" TrueType="yes" />
            </Component>
     </DirectoryRef>
</Fragment>

它将文件添加到正确的位置,但构建您的解决方案将产生一个ICE07验证警告,抱怨 TTF 字体文件必须放在 Windows 字体文件夹中。

鉴于这是一种网络字体,不应该去那里,这很烦人,但幸运的是,因为它是一种网络字体,你需要它以多种格式来安抚 IE、Edge、Chrome、Firefox 等......这意味着你可以制作使用存在的非 TTF 字体变体来消除警告。

像这样重构片段:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <DirectoryRef Id="WebsiteFontsDir">
            <Component Id="CMP_WebsiteFonts" Guid="{********-482C-4924-B06E-9FAC34F89D1D}" KeyPath="yes">
                <File Id="glyphicons_halflings_regular.eot" Source="$(var.AZViewerModule.TargetDir)fonts\glyphicons-halflings-regular.eot" />
                <File Id="glyphicons_halflings_regular.svg" Source="$(var.AZViewerModule.TargetDir)fonts\glyphicons-halflings-regular.svg" />
                <File Id="glyphicons_halflings_regular.woff" Source="$(var.AZViewerModule.TargetDir)fonts\glyphicons-halflings-regular.woff" />
            </Component>
            <Component Id="CMP_WebsiteFonts2" Guid="{********-BFFE-441D-B8F4-156DD596B09F}">
                <File Id="glyphicons_halflings_regular.ttf" 
                  Source="$(var.ViewerModule.TargetDir)fonts\glyphicons-halflings-regular.ttf" 
                  TrueType="no" 
                  KeyPath="no"
                  CompanionFile="glyphicons_halflings_regular.eot"/>
            </Component>
        </DirectoryRef>
    </Fragment>
</Wix>

在这里,我们否认它是 TTF 字体,并为其提供一个伴随文件,该文件是其他 Web 字体文件之一。一切都安装在您期望的位置,并且不会产生 ICE07。

于 2016-10-12T10:06:55.873 回答
2
<Directory Id="WixWorkshop" Name="WixWorkshop">
  <Component Id="Component1" Guid="DE1705EF-B96A-4746-AA9F-2C9D598E7D08">
    <File Id="File1" Name="arial.ttf" Source="arial.ttf" KeyPath="yes"/>
  </Component>
</Directory>

效果很好 - 任何组件都应该引用目录

于 2012-10-31T08:00:42.840 回答