Hey all, I upgraded my project to 3.8.1, and now, when I try to publish using msbuild’s PublishSingleFile parameter, I get many files, not just one.
Here’s the project where I recreated the issue. All I did was use the new 3.8.1 Visual Studio Extension templates to create a “MonoGame Cross-Platform Desktop Application.” To demonstrate that the Content folder still appears as well, I added a single image to the Content folder and referenced it in Content.mgcb.
Hi Amasa. As far as I know, you did as much as you could with the native PublishSingleFile. The .pdb, as you mentioned, is a debug file you can delete, but the other two files are required for DesktopGL’s graphics and audio, respectively. All other necessary .NET .dlls are included in the .exe, so it can run right away on any computer with Windows 7 SP1 or better, and OpenGL 2.1 or better.
There might be a solution for packing the exe and dlls together, like UPX Packer. If you want to include the Content too, you could try Enigma Virtual Box, as described in this Reddit thread.
I guess my confusion right now stems from the fact that, before I upgraded my project to MonoGame 3.8.1 and .NET 6.0, using PublishSingleFile did, in fact, publish exactly one file, like I expected it to. Here’s a project demonstrating the behavior my project exhibits right now when built with PublishSingleFile:
You can use the same command line command from my first post. On this project (using .NET Core 3.1), it will generate a single executable file, like this:
Since .NET Core 3.1 went out of support on Dec 22, I would like to upgrade to stay current.
Also, after some testing just now, I discovered that using .NET 6.0 with MonoGame 3.8.0 will also cause extra files besides the executable to appear when using PublishSingleFile. So, it seems like it might be an issue with how MonoGame interacts with .NET 6.0, as opposed to how MonoGame interacted with .NET Core 3.1?
Why should upgrading my project to .NET 6.0 make PublishSingleFile not work correctly with MonoGame, when it worked before? Have I set up my project wrong, or am I building it wrong, or is this a bug in MonoGame that needs to be fixed?
I can confirm that MonoGame 3.8.0 with .NET Core 3.1 builds all Content and dlls into a single executable package. Worked with your project and one of my older ones.
I don’t know why .NET 6 no longer packs content or all the assemblies anymore, but remember that upgrading to 3.8.1 and .NET 6 is optional. You can stick with MonoGame 3.8, or build your own custom source based on 3.8 but cherry-picking newer commits that are useful to you.
End of .NET support may not matter that much either, as XNA/.NET 4 games like Bastion, and MG 3.8/.NET 5 (for which support ended last May) games like Stardew Valley are still being sold. And if you wanted to stay current by pushing an update every time a new .NET releases, some users might stick to your old releases anyway. You may have to choose one .NET that’s good enough for you and your users that avoids all the stress that comes from upgrading and possibly breaking your project, and it seems like .NET Core 3.1 meets your needs.