Building with PublishSingleFile on 3.8.1 doesn't create a single executable file

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.

Link to the .zip file with project that reproduces the issue

I use this command in the command line to build the project:

dotnet publish MonoGamePublishSingleFileExample.csproj -c Release /p:PublishSingleFile=true --self-contained --output "build"

After I run that command, here are the files in the output folder:

monogame_community_bug_screenshot

I would expect just the .exe to be there, or the .exe with some debug symbol files.

How can I use PublishSingleFile in MonoGame 3.8.1? Does this work for anyone else, and not just me? What next steps can I try to get this working?

Thank you very much for your help! :slight_smile:

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.

Thank you for your response!

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:

Link to a .zip file with a .NET Core 3.1 project with MonoGame 3.8.0 that correctly publishes a single .exe using 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:

monogame_community_bug_screenshot_2

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?

Thanks so much! :slight_smile:

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.

1 Like

Thank you for confirming that .NET 6 no longer packs content for you too.

For now, I’m ignoring this issue for my project, upgrading to .NET 6, and living with the multiple files in the game build.

Ideally I’d like to have my .exe be a true single file, but I’ll return to this when I have time to.

If anyone discovers anything new about this issue in the meantime, please let me know so I can mark a solution to this!

Thank you so much. :slight_smile: