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

时间:2017-01-28 09:51:25

标签: c# xna monogame

在其他C#项目中,例如Window FormsWPF,我可以将构建的exe文件复制到其他具有.net的环境中,并且运行时没有错误。

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

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

1 个答案:

答案 0 :(得分:2)

实际上,它可以通过两个步骤来实现。

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

    使用NuGet安装Costura.Fody可以轻松实现这一目标。

    在Package Manager控制台中键入以下行

    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");
      
    5. 来源:Loading Content Within a Game Library

相关问题