Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use a resources file in MonoDevelop?

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

like image 343
Ronaldo Nascimento Avatar asked Dec 08 '10 01:12

Ronaldo Nascimento


1 Answers

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

like image 123
Gustavo Rubio Avatar answered Nov 10 '22 00:11

Gustavo Rubio