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

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

问题描述

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

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

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

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

我可以使用Razor类库或其他方式在多个Razor Page项目中以某种方式重用CSS(我的目的是,多个网站使用相同的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 Class Library项目中创建文件夹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是正确的,

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天全站免登陆