如何使用新的csproj方法在nuget包中分发字体以创建nuget包? [英] How do I distribute a font in a nuget package using the new csproj approach to create nuget packages?

查看:39
本文介绍了如何使用新的csproj方法在nuget包中分发字体以创建nuget包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Xamarin Forms(ios和android)的nuget包,我想通过该包分发自定义字体.我从nuget文档中找不到如何在nuget程序包中包含该字体,以便将其添加到使用该程序包的iOS或Android项目中.这有可能吗?如果可以,怎么办?

解决方案

如何使用新的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"><元数据>< id> MyFontPackage</id>< version> 1.0.0</version>< authors> Tester</authors><所有者>测试器</owners>< requireLicenseAcceptance> false</requireLicenseAcceptance><说明>包装说明</说明>< contentFiles><文件包括="any/any/Fonts/xx.ttf" buildAction ="content" flatten ="true" copyToOutput ="false"/></contentFiles></元数据><文件>< file src ="contentFiles/any/any/Fonts/xx.ttf" target ="contentFiles/any/any/Fonts"/></files></package> 

检查文档

检查文档 NuGet打包并还原为MSBuild目标了解更多详细信息.

希望这会有所帮助.

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?

解决方案

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.

这篇关于如何使用新的csproj方法在nuget包中分发字体以创建nuget包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆