How do I distribute a font in a nuget package using the new csproj approach to create nuget packages?

我是研究僧i 提交于 2021-02-08 09:36:05

问题


I have a nuget package for Xamarin Forms (ios and android) with which I want to distribute a custom font. I can't find from the nuget documentation how I can include the font in the nuget package so that it gets added to the iOS or Android project that consumes the package. Is this even possible? If so, how?


回答1:


How do I distribute a font in a nuget package using the new csproj approach to create nuget packages?

To include the font in the nuget package and use it in the new csproj iOS or Android project, you should use contentFiles to include the font file in the .nuspec file, like:

<?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>

Check the document NuGet ContentFiles Demystified and another thread for some more details.

Update:

If you are creating the nuget package directly from the new sdk style csproj, you can add following in your .csproj, then re-create the package, the font file will be added to the nuget package:

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

This file added as content file:

Check the document NuGet pack and restore as MSBuild targets for some more details.

Hope this helps.



来源:https://stackoverflow.com/questions/54091668/how-do-i-distribute-a-font-in-a-nuget-package-using-the-new-csproj-approach-to-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!