c# - 如何捆绑项目文件夹外部的文件夹

标签 c# .net asp.net-mvc asp.net-mvc-4

我们有多个相互链接的 .NET MVC 项目,但一些脚本和 css 文件对于所有项目都是相同的。 文件夹结构如下

- Root folder
    - Assets
        - Js
        - CSS
    - Project 1
    - Project 2
    - Project 3

所有常见的 js 都位于 Assets/js 和 Assers/Css 文件夹内,该文件夹位于项目文件夹之外。 我们可以将 Assets 文件夹捆绑到项目 1,2 和 3 中吗?

感谢您提前提供的任何提示/指导。

最佳答案

是的,你可以。您只需要在每个项目的 App_Start\BundleConfig.cs 文件中添加一些代码即可。

像这样,您在方法RegisterBundles中添加:

public static void RegisterBundles(BundleCollection bundles)
{
 bundles.Add(new ScriptBundle("Root/Assets/js").Include(
             "Root/Assets/Js/*.js")); //You put your path where there is the Root

 bundles.Add(new StyleBundle("Root/Assets/css").Include(
             "Root/Assets/CSS/*.css")); //You put your path where there is the Root



     // Code removed for clarity.
}

然后你可以将这些行放入每个 Layout.cshtml

@Styles.Render("Root/Assets/css")
@Scripts.Render("Root/Assets/js")

调用您的 Js 库和 CSS 文件。

希望对你有帮助

关于c# - 如何捆绑项目文件夹外部的文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23241422/

相关文章:

c# - Web API 反序列化正在将 int 转换为字符串,我该如何防止呢?

c# - 归档数千个文件和 7zip 限制

asp.net-mvc - ASP.NET MVC 重复任务

asp.net-mvc - 统一 MVC 和 Web Api - View 和 json 的 Controller 相同吗?

c# - 在不对字段或方向进行硬编码的情况下订购列表

c# - Visual Studio 调试器未进入 .NET 框架源代码

.net - Kubernetes pod 中的时间是几点?

c# - `this` 和类构造函数

c# - 如何从 C# 代码中拉伸(stretch) DataGrid 列?

c# - 如何跨 Visual Studio 项目初始化自动映射器