Razor 类库也可以打包静态文件(js、css 等)吗? [英] Can Razor Class Library pack static files (js, css etc) too?

查看:35
本文介绍了Razor 类库也可以打包静态文件(js、css 等)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许 已经重复了,但由于该帖子没有任何答案,我发布了这个问题.

Maybe duplicate of this already, but since that post does not have any answer, I am posting this question.

新的 Razor 类库很棒,但它不能打包库文件(如jQuery、共享CSS).

The new Razor Class Library is awesome, but it cannot pack libraries files (like jQuery, shared CSS).

我能否以某种方式在多个 Razor Page 项目中重用 CSS,使用 Razor 类库或其他任何东西(我的目的是,多个网站使用相同的 CSS,并且单个更改适用于所有项目).

Can I somehow reuse the CSS across multiple Razor Page projects, either using Razor Class Library or anything else (my purpose is that, multiple websites use the same CSS, and a single change applies to all projects).

我尝试在 Razor 类库项目中创建文件夹 wwwroot,但它没有按预期工作(我可以理解为什么它不应该工作).

I have tried creating the folder wwwroot in the Razor Class Library project, but it does not work as expected (I can understand why it should not work).

推荐答案

Ehsan 的回答在提问时是正确的(对于 .NET Core 2.2),对于 .NET Core 3.0,RCL 可以毫不费力地包含静态资产:

Ehsan answer was correct at the time of asking (for .NET Core 2.2), for .NET Core 3.0, RCL can include static assets without much effort:

要将配套资源作为 RCL 的一部分包含在内,请在类库中创建一个 wwwroot 文件夹,并在该文件夹中包含所有必需的文件.

To include companion assets as part of an RCL, create a wwwroot folder in the class library and include any required files in that folder.

打包 RCL 时,wwwroot 文件夹中的所有配套资产都会自动包含在包中.

When packing an RCL, all companion assets in the wwwroot folder are automatically included in the package.

包含在 RCL 的 wwwroot 文件夹中的文件在前缀 _content/{LIBRARY NAME}/下暴露给消费应用程序.例如,名为 Razor.Class.Lib 的库会生成指向 _content/Razor.Class.Lib/处的静态内容的路径.

The files included in the wwwroot folder of the RCL are exposed to the consuming app under the prefix _content/{LIBRARY NAME}/. For example, a library named Razor.Class.Lib results in a path to static content at _content/Razor.Class.Lib/.

这篇关于Razor 类库也可以打包静态文件(js、css 等)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆