Image as resource in Asp.Net 5 class library

一个人想着一个人 提交于 2019-12-04 03:39:51

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/31972571/image-as-resource-in-asp-net-5-class-library

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