问题
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