简体   繁体   English

在Monogame中将dll和内容嵌入exe

[英]Embed dlls and contents into exe in monogame

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. 在诸如Window FormsWPF类的其他C#项目中,我可以将生成的exe复制到具有.net的其他环境中,并且可以正常运行。

However, in MonoGame , the exe file requires a lot of dlls and needs the content folder to run successfully. 但是,在MonoGame ,exe文件需要很多dll,并且需要content文件夹才能成功运行。

Is there a way to include the dlls and contents inside the exe? 有没有办法在exe文件中包含dll和内容?

Actually, it can be achieved by 2 steps. 实际上,它可以通过两个步骤来实现。

  1. Embedding the dlls. 嵌入dll。
  2. Including the contents. 包括内容。

Embedding the dlls 嵌入dll

This can be easily achieved by installing Costura.Fody using NuGet. 这可以通过使用NuGet安装Costura.Fody轻松实现。

Type the following line to the Package Manager Console 在Package Manager控制台中输入以下行

Install-Package Costura.Fody

Source: Embedding DLLs in a compiled executable . 来源:将DLL嵌入已编译的可执行文件中

Including the contents 包括内容

  1. Copy your compiled content files ( .xnb files and other contents) to your Content folder. 将已编译的内容文件( .xnb文件和其他内容)复制到Content文件夹中。
  2. Go to the project property page and add your compiled content files to your resources. 转到项目属性页面,然后将已编译的内容文件添加到资源中。
  3. 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; } 
  4. Finished! 完了! You can now load content using the old method 您现在可以使用旧方法加载内容

     Content.Load<Texture2D>("Image1"); 

Source: Loading Content Within a Game Library 来源: 在游戏库中加载内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM