How do I use a resources file in MonoDevelop?

天大地大妈咪最大 提交于 2019-12-22 06:40:26

问题


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. format the .resources file (is it something like string1="Hello world")?
  2. embed the file in the EXE
  3. read the embedded file (ResourceReader.GetResourceData wants a file)

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


回答1:


There are two ways:

Easy way:

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.

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.

Not so easy way:

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>

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



来源:https://stackoverflow.com/questions/4383298/how-do-i-use-a-resources-file-in-monodevelop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!