In other C# projects such as Window Forms
and WPF
, I can just copy the built exe to other environment with .net and run without errors.
However, in MonoGame
, the exe file requires a lot of dlls and needs the content folder to run successfully.
Is there a way to include the dlls and contents inside the exe?
Actually, it can be achieved by 2 steps.
Embedding the dlls
This can be easily achieved by installing Costura.Fody using NuGet.
Type the following line to the Package Manager Console
Install-Package Costura.Fody
Source: Embedding DLLs in a compiled executable.
Including the contents
.xnb
files and other contents) to your Content
folder.Replace the code below:
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
with
public Game1()
{
graphics = new GraphicsDeviceManager(this);
ResourceContentManager resxContent;
resxContent = new ResourceContentManager(Services, Resources.ResourceManager);
Content = resxContent;
}
Finished! You can now load content using the old method
Content.Load<Texture2D>("Image1");