问题
Using MVC4, I've created a controller for css files, so that I can pass a model in to them and use razor syntax within css.
In order not to break existing css files, these special css files do not exist at the path they are requested from.
I've tried to include these files in a bundle, and they do not appear in the page output.
bundles.Add(New StyleBundle("~/Content/site/css").Include("~/Styles/site.css"))
Note that ~/Styles/site.css does not exist on disk. However, the StylesController handles this correctly and returns the expected content if you ask for it.
My guess is that the bundler sees that there's no file on disk and excludes that path from the output. But I don't know how to make it not care about that.
Any thoughts on how to get these files to play nice with bundles?
回答1:
Try like this
bundles.Add(New StyleBundle("~/Content/site/css")
.Include("~/Styles/site.css",new CssRewriteUrlTransform()))
回答2:
I know this question is old, but I hit this roadblock in trying to include the client-side validation bundle in each page without manually including each file. As CssRewriteUrlTransform didn`t seem to do anything for me, I used the next class
public class CustomScriptBundle : ScriptBundle
{
public CustomScriptBundle(string virtualPath, IBundleOrderer orderer)
: base(virtualPath)
{
Orderer = orderer;
}
public CustomScriptBundle(string virtualPath)
: this(virtualPath, new NonOrderingBundleOrderer())
{
}
public CustomScriptBundle IncludeVirtual(string virtualPath)
{
this.Include(new BundleResolver().GetBundleContents(virtualPath).ToArray());
return this;
}
}
p.s. : NonOrderingBundleOrderer is a class that doesn`t order the files included in the bundle alphabetically
来源:https://stackoverflow.com/questions/21323373/is-it-possible-to-include-virtual-resources-in-a-bundle