【发布时间】:2017-01-28 09:51:24
【问题描述】:
在Window Forms和WPF等其他C#项目中,我可以直接将构建好的exe复制到其他环境中,使用.net运行,没有错误。
但是在MonoGame中,exe文件需要很多dll,需要内容文件夹才能成功运行。
有没有办法在 exe 中包含 dll 和内容?
【问题讨论】:
在Window Forms和WPF等其他C#项目中,我可以直接将构建好的exe复制到其他环境中,使用.net运行,没有错误。
但是在MonoGame中,exe文件需要很多dll,需要内容文件夹才能成功运行。
有没有办法在 exe 中包含 dll 和内容?
【问题讨论】:
其实分两步就可以实现。
嵌入 dll
这可以通过使用 NuGet 安装 Costura.Fody 轻松实现。
在包管理器控制台中键入以下行
Install-Package Costura.Fody
来源:Embedding DLLs in a compiled executable。
包括内容
.xnb 文件和其他内容)复制到您的 Content 文件夹中。替换下面的代码:
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;
}
完成!您现在可以使用旧方法加载内容
Content.Load<Texture2D>("Image1");
【讨论】: