Skip to content

Instantly share code, notes, and snippets.

@spooky
Created December 10, 2012 14:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save spooky/4250921 to your computer and use it in GitHub Desktop.
Save spooky/4250921 to your computer and use it in GitHub Desktop.
a hack to make mvc4 bundling work with mvc contrib portable areas
public class Rebundler
{
private readonly Assembly assembly;
private readonly string virtualPath;
private readonly HashSet<string> resourceNames = new HashSet<string>();
public Rebundler(Assembly assembly, string virtualPath)
{
this.assembly = assembly;
this.virtualPath = virtualPath;
}
public Rebundler Include(params string[] includes)
{
foreach (var include in includes)
{
resourceNames.Add(include);
}
return this;
}
public Bundle Rebundle()
{
var names = assembly.GetManifestResourceNames().Where(n => resourceNames.Any(n.EndsWith));
var path = HttpContext.Current.Server.MapPath("~/Static");
var bundle = new Bundle(virtualPath);
foreach (var resource in names)
{
using (var stream = assembly.GetManifestResourceStream(resource))
{
if (stream == null)
continue;
var resourcePath = Path.Combine(path, resource);
using (var file = new FileStream(resourcePath, FileMode.Create))
{
stream.CopyTo(file);
file.Close();
}
bundle.Include("~/Static/" + resource);
}
}
return bundle;
}
}
@neo125874
Copy link

I'm sorry to bother you, but i want to fork your source and do some adjustment then add other class, if you have any problem, please let me know, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment