在簡單的ASP.Net MVC4測試應用程序中,我安裝了無點的NuGet包和followed this tutorial。ASP.Net MVC4包,當調試設置爲false時,不會呈現較少文件
我的.less
文件被正確解析爲CSS,並且在debug=true
時正常工作。
<link href="/Public/less/main.less" rel="stylesheet"/>
<link href="/Public/less/home.less" rel="stylesheet"/>
<link href="/Public/less/a.less" rel="stylesheet"/>
<link href="/Public/less/b.less" rel="stylesheet"/>
<link href="/Public/less/c.less" rel="stylesheet"/>
然而,當我爲了讓它運行如下,並結合到一個樣式表設置debug=false
,我得到這個:
<link href="/Public/less?v=" rel="stylesheet"/> // NOT WORKING!
這是我的包配置文件;
public class BundleConfig
{
// For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
public static void RegisterBundles(BundleCollection bundles)
{
// Compile .less files and create a bundle for them.
var lessBundle = new Bundle("~/Public/less").Include(
"~/Public/less/main.less",
"~/Public/less/home.less",
"~/Public/less/a.less",
"~/Public/less/b.less",
"~/Public/less/c.less");
lessBundle.Transforms.Add(new LessTransform());
lessBundle.Transforms.Add(new CssMinify());
bundles.Add(lessBundle);
}
}
而且在我的佈局文件:再次,直接從教程採取
<head>
@Styles.Render("~/Public/less")
</head>
這是我的LessTransform類:
public class LessTransform : IBundleTransform
{
public void Process(BundleContext context, BundleResponse response)
{
response.Content = dotless.Core.Less.Parse(response.Content);
response.ContentType = "text/css";
}
}
爲什麼捆綁任何想法在debug=false
上工作不正常?
你可以試試這個答案:http://stackoverflow.com/questions/9593254/mvc4-less-bundle-import-directory他使用BundleTransformer.Less包。它可能會幫助你... – freshbm 2013-03-25 14:33:57