我如何使用MonoDevelop的一个资源文件? [英] How do I use a resources file in MonoDevelop?

查看:225
本文介绍了我如何使用MonoDevelop的一个资源文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用MonoDevelop的C#和嵌入一个资源文件(你知道拥有的.resources扩展的)。我想要的资源文件包含字符串的应用程序在运行时读取。我想将它们嵌入在EXE。但我不能想出如何

Trying to use MonoDevelop C# and embed a resources file (you know the one that has the .resources extension). I want the res file to contain strings for the app to read at runtime. I want to embed them in the EXE. But I cant figure out how to


  1. 格式化.resources文件(它是像字符串1 =的Hello world)?

  2. 在文件中嵌入的EXE

  3. 读取嵌入的文件(ResourceReader.GetResourceData想要一个文件)

否则,我想我会放弃这个想法,只是把文字在我自己的文本文件。
谢谢

Otherwise I guess I will abandon this idea and just put the text in my own text file. Thanks

推荐答案

有两种方式:

轻松的方式:

转到解决方案,侧边栏,然后右键单击覆盖要嵌入的资源活在项目名称,然后在上下文菜单去添加 - >添加文件,然后选择要添加的文件。如果你不想自己身边的根项目文件夹,这个过程是在添加的文件夹,而不是项目名称相同的只是点击右键,你可以添加文件夹。

Go to solution sidebar and right click over the project name where you want the embedded resource to live in and in the contextual menu go to to Add -> Add Files and select the files you want to add. You can add a folder if you dont want them around the root project folder and the process is the same just right click over the added folder instead of the project name.

在做到这一点选择该文件(S),然后在属性侧边栏你会看到几个选项,改变建设行动,以嵌入的资源和你做。其实你会发现更多有用的选项有

Once that is done select the file(s) and in the properties sidebar you'll see several options, change the "Build action" to "Embed as resource" and you are done. Actually you'll find more helpful options there.

没那么简单的方法:

编辑.csproj的文件,该文件是在项目的根文件夹,并添加文件是这样的:

Edit your .csproj file which is in the root folder of the project and add the files like this:

  <ItemGroup>
    <EmbeddedResource Include="Resources\file1.txt" />
    <EmbeddedResource Include="Resources\file2.txt" />
  </ItemGroup>

请注意,有拆分文件夹名和文件名反斜杠。该的ItemGroup元素及其子女应低于主<的任何地方;项目> 标签

Note that there is a backslash to split folder name and filename. The ItemGroup element and its children should be anywhere below the main <Project> tag

这篇关于我如何使用MonoDevelop的一个资源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆