Trimming/Linker breaks SpriteFont loading

I believe I’ve found a solution for this. After ripping into the SpriteFont’s XNB, I discovered that the MG content loader uses System.Char by reflection when loading SpriteFonts. So, stop the linker from removing it. I tried a couple methods to only block the trimming of the System.Char type without luck. I would be interested if anyone else is doing this a bit cleaner. Here’s what you can do:

Create an XML file (ex: TrimmerRoots.xml) with this content:

<linker>
	<assembly fullname="System.Private.CoreLib" preserve="all" />
	<assembly fullname="mscorlib" preserve="all" />
</linker>

Then reference that in your .csproj with:

<ItemGroup>
	<TrimmerRootDescriptor Include="TrimmerRoots.xml" />
</ItemGroup>
4 Likes