【问题标题】:How do I distribute a font in a nuget package using the new csproj approach to create nuget packages?如何使用新的 csproj 方法在 nuget 包中分发字体以创建 nuget 包?
【发布时间】:2019-01-08 12:18:02
【问题描述】:

我有一个用于 Xamarin Forms(ios 和 android)的 nuget 包,我想用它分发自定义字体。我无法从 nuget 文档中找到如何将字体包含在 nuget 包中,以便将其添加到使用该包的 iOS 或 Android 项目中。这甚至可能吗?如果有,怎么做?

【问题讨论】:

  • 我对 Xamarin 表单一无所知。字体通常如何包含在项目中,它如何与 msbuild 集成?如果它只是 csproj 中的 <Content ... /> 项,那么您应该查看 NuGet 的内容和 contentFiles。否则,我需要更多信息。

标签: visual-studio xamarin.forms nuget csproj


【解决方案1】:

如何使用新的 csproj 方法在 nuget 包中分发字体以创建 nuget 包?

要将字体包含在 nuget 包中并在新的 csproj iOS 或 Android 项目中使用,您应该使用 contentFiles 将字体文件包含在 .nuspec 文件中,例如:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
  <metadata>
    <id>MyFontPackage</id>
    <version>1.0.0</version>
    <authors>Tester</authors>
    <owners>Tester</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package Description</description>
    <contentFiles>
      <files include="any/any/Fonts/xx.ttf" buildAction="content" flatten="true" copyToOutput="false"/>
    </contentFiles>
  </metadata>

  <files>
    <file src="contentFiles/any/any/Fonts/xx.ttf" target="contentFiles/any/any/Fonts" />
  </files>
</package>

查看文档NuGet ContentFiles Demystifiedanother thread 了解更多详情。

更新:

如果您是直接从新的 sdk 样式 csproj 创建 nuget 包,您可以在 .csproj 中添加以下内容,然后重新创建包,字体文件将添加到 nuget 包中:

  <ItemGroup>
    <None Include="font\test.ttf" Pack="true"/>
  </ItemGroup>

此文件已添加为内容文件:

查看文档NuGet pack and restore as MSBuild targets 了解更多详情。

希望这会有所帮助。

【讨论】:

  • 感谢 Leo,但我没有使用 nuspec,而是直接从新的 sdk 样式 csproj 创建 nuget 包。我会看看你建议的链接。
  • @JohnB,我已经为您的评论更新了我的答案,看看它是否对您有帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多