How to build a self contained executable

When you build the game it comes with all of the dll’s inside the folder, is there a way to just make it a single exe file that can run wherever

If you are using Visual Studio 2022, there is an option to produce a single file when you publish.
image

Publish Selection bring up this:

You may need self-contained also so that the user doesn’t have to pre-install the .NET runtimes.

I did it that way and now the publish folder looks like this:


it won’t run outside this folder, i’ve tried many different approuches to this but it always ended up with a dependent exe file

Obligatory plug of “it generally isn’t a good idea to embed everything into a single EXE blah blah blah load times blah blah other stuff blah”.

That said, to accomplish this you need to do the steps above, but also have to set all your references to build within the binary as well. That means 3rd party libs (your DLLs) need to not “copy to output directory” and your content will need to be embedded resources. With your content being embedded resources you’ll need to write a new ContentManager to load from embedded resources instead of files (this sounds tougher than it actually is, you can just write a class that inherits from ContentManager and override the GetResourceStream method or some such if memory serves).

1 Like