<PublishTrimmed> broke the executable

Hello, i started to play around with monoGame in the last days, other than looking the feature it has to offer i tested different compilation arguments to see how small can a final publish folder become.

I read about this PublishTrimmed argument that use the IL Linker from what i’ve undertood.
Adding it to the csproj file or calling it from the terminal just work, the final folder is half the size of the previous compialtion, the only problem is that the game dosen’t start anymore.

I also tried doing the same on the samples project on github, and the result is the same, it work, but can’t start the game exe.
Opening it form the terminal doesn’t give any error or text.
Searching online haven’t helped me, someone only suggested to use and specify every DLL used in the project, but even doing so dosen’t work.

I’m working with .NET core 3.1 and MonoGame 3.8.0.1641

Is this something related to monoGame? or to .NET? or to my project?
Can someone help me to figure this out?

You’ll need to add an rd.xml file to tell it not to trim out either your Content or the required file mscorlib.dll. You can use the one I linked or paste the following into a text editor and save it in the folder with your .csproj as rd.xml:

<Directives>
    <Application>
        <Assembly Name="MonoGame.Framework">
            <Type Name="Microsoft.Xna.Framework.Content.ListReader`1[[System.Char,mscorlib]]" Dynamic="Required All" />
        </Assembly>
        <Assembly Name="mscorlib" />
    </Application>
</Directives>

Then, add this to your .csproj file:

<ItemGroup>
    <RdXmlFile Include="rd.xml" />
  </ItemGroup>

This works for MonoGame 3.8 and 3.8.1. You should find that your game and all your Content works when trimmed!

1 Like