Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image as resource in Asp.Net 5 class library

In .net 4.5 i was able to add a resource file to my project, add images as bitmaps to this resource file and access them by Properties.Resources.ImageName. How do i compile images in 4.6 dnx?

Thanks in advance!

like image 239
Toke Emil Heldbo Reines Avatar asked Aug 12 '15 18:08

Toke Emil Heldbo Reines


1 Answers

You can specify the files that will be compiled into the assembly under the "resources" section in project.json, like so:

"resources": [
    "path/to/yourfile.png"
],

After which, assuming your project's name is YourProject, the file can be accessed via:

const string path = "YourProject.path.to.yourfile.png";
Assembly.GetExecutingAssembly().GetManifestResourceStream(path)

Note how the slashes in the filesystem path are converted into periods in the resource path.

Note: In 1.0.0-rc1 (and possibly -beta8, haven't checked) the project setting is renamed from resources to resource

like image 85
Rytmis Avatar answered Nov 10 '22 06:11

Rytmis