c# - 将 dll 和内容嵌入到 monogame 的 exe 中

标签 c# xna monogame

在其他 C# 项目中,例如 Window FormsWPF,我只需将构建的 exe 复制到其他 .net 环境即可运行,不会出现错误。

但是,在MonoGame中,exe文件需要大量的dll,并且需要content文件夹才能成功运行。

有没有办法将dll和内容包含在exe中?

最佳答案

其实只需2步就可以实现。

  1. 嵌入 dll。
  2. 包括内容。

嵌入 dll

这可以通过安装 Costura.Fody 轻松实现使用 NuGet。

在包管理器控制台中键入以下行

Install-Package Costura.Fody

来源:Embedding DLLs in a compiled executable .

包含内容

  1. 将编译的内容文件(.xnb 文件和其他内容)复制到 Content 文件夹。
  2. 转到项目属性页面并将编译的内容文件添加到您的资源中。
  3. 替换下面的代码:

    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
    }
    

    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        ResourceContentManager resxContent;
        resxContent = new ResourceContentManager(Services, Resources.ResourceManager);
        Content = resxContent;
    }
    
  4. 完成了!您现在可以使用旧方法加载内容

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

来源:Loading Content Within a Game Library

关于c# - 将 dll 和内容嵌入到 monogame 的 exe 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41908427/

相关文章:

c# - 在 C# 中传递 IntPtr 指针后,在非托管 C++ 代码中分配数组,编码(marshal)处理类型

c# - 如何在 C# 中自动删除临时文件?

c# - XNA C# 如何让我的模型闪烁?

c# - 是否可以在自定义 XNA 内容处理器中定义 Assets 名称?

c# - 如何设置 web.config 并使用 ASP.NET ResetPassword() 方法

c# - 在 ASP.NET C# 中添加视频

algorithm - 太空入侵者碰撞检测。 1颗子弹检查所有入侵者?

c# - Windows Phone 8 MonoGame 初始化未被调用

c# - XNA Texture2D 缓存

C# XNA - 用于 tilemap 的 int[,] 数组或 Tile[,] 数组