【发布时间】:2015-08-12 18:17:10
【问题描述】:
在 .net 4.5 中,我能够将资源文件添加到我的项目中,将图像作为位图添加到该资源文件并通过 Properties.Resources.ImageName 访问它们。如何在 4.6 dnx 中编译图像?
提前致谢!
【问题讨论】:
标签: asp.net .net resources asp.net-core dnx
在 .net 4.5 中,我能够将资源文件添加到我的项目中,将图像作为位图添加到该资源文件并通过 Properties.Resources.ImageName 访问它们。如何在 4.6 dnx 中编译图像?
提前致谢!
【问题讨论】:
标签: asp.net .net resources asp.net-core dnx
您可以在 project.json 的“资源”部分下指定将编译到程序集中的文件,如下所示:
"resources": [
"path/to/yourfile.png"
],
之后,假设您的项目名称为 YourProject,则可以通过以下方式访问该文件:
const string path = "YourProject.path.to.yourfile.png";
Assembly.GetExecutingAssembly().GetManifestResourceStream(path)
注意文件系统路径中的斜杠如何转换为资源路径中的句点。
注意:在 1.0.0-rc1(可能还有 -beta8,尚未检查)中,项目设置从 resources 重命名为 resource
【讨论】:
resources 现在已被弃用,取而代之的是embed 下的buildOptions。