使用Wix将字体安装到本地字体文件夹

Kyz*_*zou 18 fonts wix

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

添加字体时,WiX会选择.ttf扩展名并要求您将其安装到本地Font文件夹中(当使用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>
Run Code Online (Sandbox Code Playgroud)

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

错误LGHT1076:ICE60:文件font.ttf不是Font,其版本不是伴随文件引用.它应该具有语言列中指定的语言.

Kyz*_*zou 12

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

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

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

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

light.exe -sice:ICE07
Run Code Online (Sandbox Code Playgroud)

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


Che*_*rra 5

你可以用VS实现同样的目的:

右键单击"安装项目",单击"属性".

选择工具设置选项卡.

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

[ICE60]

要么

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

[-sice:ICE60]


Pet*_*nes 5

对于bootstrap 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>
Run Code Online (Sandbox Code Playgroud)

它会将文件添加到正确的位置,但构建您的解决方案将产生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>
Run Code Online (Sandbox Code Playgroud)

在这里,我们拒绝使用 TTF 字体,并为其提供一个配套文件,该文件是其他 Web 字体文件之一。一切都安装在您期望的位置,并且不会产生 ICE07。