Image as resource in Asp.Net 5 class library

我怕爱的太早我们不能终老 提交于 2019-12-01 19:17:53

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

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