【问题标题】:Image as resource in Asp.Net 5 class library图像作为 Asp.Net 5 类库中的资源
【发布时间】:2015-08-12 18:17:10
【问题描述】:

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

提前致谢!

【问题讨论】:

    标签: asp.net .net resources asp.net-core dnx


    【解决方案1】:

    您可以在 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
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-04
    • 2012-04-27
    相关资源
    最近更新 更多