我正在开发一个MVC4应用程序,我正在使用WebOptimization来完成所有资源处理(cat和min)。我有几个非常相似的页面,但在逐页的基础上需要一些不同的样式。
所以,我试图在另一个包(特定于页面的样式)中引用一个包(基本样式),而且我没有太多运气。这是我在捆绑配置中的内容:
bundles.Add(new StyleBundle("~/bundles/css/search").Include(
"~/Content/css/partials/grid-controls.css",
"~/Content/css/partials/grid.css",
"~/Content/css/views/search.css"));
bundles.Add(new StyleBundle("~/bundles/css/searchtrees").Include(
"~/bundles/css/search",
"~/Content/css/views/search/trees.css"));
在搜索树页面上,我得到了trees.css,但没有基本搜索CSS包。
如何在第二个包中引用第一个包?我确定有一种方法,只是不太熟悉捆绑。
答案 0 :(得分:8)
您可以重复使用文件引用,而不是引用另一个包。像这样:
var baseIncludes = new string [] { "~/Content/css/partials/grid-controls.css", "~/Content/css/partials/grid.css", "~/Content/css/views/search.css" };
// 'base' bundle references the base includes
bundles.Add (new StyleBUndle ("~/bundles/css/search").Include (baseIncludes));
// other bundle references the base includes and some extras
bundles.Add (new StyleBundle ("~/bundles/css/searchtrees").Include(baseIncludes).Include ("~/Content/css/views/search/trees.css"));