Created
December 10, 2012 14:41
-
-
Save spooky/4250921 to your computer and use it in GitHub Desktop.
a hack to make mvc4 bundling work with mvc contrib portable areas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.