图像作为Asp.Net 5类库中的资源

Tok*_*nes 5 .net asp.net resources dnx asp.net-core

在.net 4.5中,我能够将资源文件添加到我的项目中,将图像作为位图添加到此资源文件中,并通过Properties.Resources.ImageName访问它们.我如何在4.6 dnx中编译图像?

提前致谢!

Ryt*_*mis 9

您可以在project.json的"resources"部分下指定将编译到程序集中的文件,如下所示:

"resources": [
    "path/to/yourfile.png"
],
Run Code Online (Sandbox Code Playgroud)

之后,假设您的项目名称是YourProject,可以通过以下方式访问该文件:

const string path = "YourProject.path.to.yourfile.png";
Assembly.GetExecutingAssembly().GetManifestResourceStream(path)
Run Code Online (Sandbox Code Playgroud)

请注意文件系统路径中的斜杠如何转换为资源路径中的句点.

注意:在1.0.0-rc1(可能是-beta8,尚未检查)中,项目设置将从重命名resourcesresource