xur*_*rca 25 asp.net-mvc bundling-and-minification
我有这样的捆绑
bundles.Add(new StyleBundle("~/Content/themes/default/css")
.IncludeDirectory("~/Content/themes/Default", "*.css"));
Run Code Online (Sandbox Code Playgroud)
但我想从中排除一个css文件.是否可以在不指定bundle中的每个css文件的情况下进行此操作?
Cof*_*ode 37
尝试使用IgnoreList.Ignore ; bundles.IgnoreList.Ignore(...).
小智 13
您可以在此处使用扩展方法:
public static class BundleExtentions
{
public static Bundle IncludeDirectoryWithExclusion(this StyleBundle bundle, string directoryVirtualPath, string searchPattern, params string[] toExclude)
{
var folderPath = HttpContext.Current.Server.MapPath(directoryVirtualPath);
foreach (var file in Directory.GetFiles(folderPath, searchPattern))
{
if (!String.IsNullOrEmpty(Array.Find(toExclude, s => s.ToLower() == file.ToLower())))
{
continue;
}
bundle.IncludeFile(directoryVirtualPath + "/" + file);
}
return bundle;
}
Run Code Online (Sandbox Code Playgroud)
然后使用应该是:
bundles.Add(new StyleBundle("~/Content/themes/default/css")
.IncludeDirectoryWithExclusion("~/Content/themes/Default", "*.css", "file-you-dont-want.css"));
Run Code Online (Sandbox Code Playgroud)
我目前不在PC上,因此上述内容未经测试,但应该为您提供解决方案的模板.