【问题标题】:Embed dlls and contents into exe in monogame在monogame中将dll和内容嵌入到exe中
【发布时间】:2017-01-28 09:51:24
【问题描述】:

Window FormsWPF等其他C#项目中,我可以直接将构建好的exe复制到其他环境中,使用.net运行,没有错误。

但是在MonoGame中,exe文件需要很多dll,需要内容文件夹才能成功运行。

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

【问题讨论】:

    标签: c# xna monogame


    【解决方案1】:

    其实分两步就可以实现。

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

    嵌入 dll

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

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

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-18
      • 2013-02-03
      • 1970-01-01
      • 1970-01-01
      • 2021-03-15
      • 2013-05-26
      相关资源
      最近更新 更多