Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a simpler syntax to access resources embedded in an assembly?
    primarykey
    data
    text
    <p>Right now I have a handful of those in a class:</p> <pre><code>string upgrade_file = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream( Assembly.GetExecutingAssembly().GetName().Name + ".schemas.template.db_upgrades.txt") ).ReadToEnd(); </code></pre> <p>I can write a wrapper function to simplify accessing embedded resources (and I will if I have to), but is there a simpler or more elegant way to access them natively with .Net? </p> <p>For example, I find it strange that GetManifestResourceStream(...) isn't static. Another example: is there some method that returns a string rather than a stream for text files?</p> <p><strong>UPDATE 1</strong>:</p> <p>To be clear, I have text files in sub-directories, and I want that:</p> <ol> <li>These files remain separate files (for example to be able to source control them separately)</li> <li>These files remain <em>embedded</em> resources, i.e. compiled with the assembly.</li> </ol> <p>Right now I'm doing this as shown in this image: <img src="https://i.stack.imgur.com/6NSaX.png" alt="enter image description here"></p> <p><strong>UPDATE 2</strong>:</p> <p>I did not manage to use anything from the answers to simplify accessing the files.</p> <p>Here is the helper method I'm now using in case someone else might find it useful:</p> <pre><code>/// &lt;summary&gt; /// Get the content of a text file embedded in the enclosing assembly. /// &lt;/summary&gt; /// &lt;param name="resource"&gt;The "path" to the text file in the format /// (e.g. subdir1.subdir2.thefile.txt)&lt;/param&gt; /// &lt;returns&gt;The file content&lt;/returns&gt; static string GetEmbeddedTextFile(string resource) { return new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream( Assembly.GetExecutingAssembly().GetName().Name + "." + resource)).ReadToEnd(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload