【问题标题】:How can I get a list of embedded static files from a Razor Class Library?如何从 Razor 类库中获取嵌入式静态文件的列表?
【发布时间】:2020-12-12 11:49:23
【问题描述】:

标题真的是问题...

我有一个嵌入式 Razor 类库,其中包含一些 CSS 文件,它们是一堆引导主题。

由于 Razor 类库将其全部内容编译到单个文件中,因此没有 File System 这样的,因此 wwwroot/css 目录中的 Directory.GetFiles 不能像在普通网站项目中那样工作。

那么,有谁知道如何在代码中获取嵌入的 CSS 文件列表?

(如果相关,THIS SO QUESTION 是我之前在这个项目的开发过程中问过的,它显示了我用来在我的 RCL 中嵌入静态文件的代码)

(项目使用.NET Core 3.0)

【问题讨论】:

    标签: asp.net-core .net-core razor-class-library


    【解决方案1】:

    我使用这些 SO 答案的组合找到了答案:

    How to get class library assembly reference in .NET Core project?

    confused about resources and GetManifestResourceNames()

     System.Reflection.Assembly assembly = System.Reflection.Assembly.GetAssembly(typeof(NameSpaceForMyRCL.Class));
     string[] names = assembly.GetManifestResourceNames();
    

    上面的代码为我提供了嵌入文件的完整列表,然后我可以使用 Linq 进行过滤

    【讨论】:

      猜你喜欢
      • 2020-11-15
      • 2021-12-14
      • 2020-02-11
      • 1970-01-01
      • 2012-02-04
      • 1970-01-01
      • 2010-11-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多