dotnet publish generates more DLLs than needed

I’m trying to distribute a simple 2D game using the official package docs

Using dotnet publish gives me a package I can distribute onto all the platforms and run the game successfully, however it generates far too many .DLLs such as System.Private.CoreLib.dll and System.Private.Xml.dll which are both 8MB and bloat the game’s size (100MB+)

Is there an easy way for me to unbloat the release and remove any unnecessary DLLs?

One approach would be for me to go through the .deps.json file and manually remove the DLLs referenced one by one until the game executable stops working but that doesn’t sound like a feasible approach

When I run my game in Release mode the only .DLLs that get generated is the game’s dll and MonoGame.Framework.dll (i.e. the project is very basic and bare)

How does everyone else distribute/publish their games to Windows/Mac/Linux? (apart from using MonoKickstart)

Because those “unnecessary” dlls allow your game to be run without installing dotnet.

Those dlls are not “generated”, they are copies from the .NET runtime and are needed to run the game. You can’t just manually take them out obviously as you have experienced, you’ll never know what dependencies you have, transitive or otherwise.

You should read up on the dotnet publish command and make sure you understand all of it. dotnet publish command - .NET CLI | Microsoft Docs

Try the following command for 64-bit windows dotnet publish --configuration Release --runtime win-x64 -p:PublishReadyToRun=true -p:PublishTrimmed=true --self-contained