Reputation: 141
Now I have several MVC4 projects. Some JS files is shared for all of this projects so I put it into dedicated assembly and copy it to each project after changes.
How I can put it into this assembly as embedded resource and extract it in my projects to use it with MVC4 bundling? (Is there any way to get files as a Bundle object)
Upvotes: 3
Views: 1932
Reputation: 775
Actually is is possible to bundle embedded resources, but it is not totally trivial:
Basically what you have to do is create a virtualpath provider that references the embedded resource and then bundle the virtual path:
See an example here: http://dotnet.dzone.com/articles/aspnet-bundlingminification
Is might also work with a controller that delivers js / css scripts, but I am not sure.
Peter
Upvotes: 2
Reputation: 1038770
How I can put it into this assembly as embedded resource and extract it in my projects to use it with MVC4 bundling?
You can't. The bundling mechanism doesn't support resources embedded into assemblies. I would recommend you hosting those shared static resources on a CDN (Content Delivery Network) and having all your applications reference them from this common CDN.
You could enable CDN support like that:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.UseCdn = true; //enable CDN support
//add link to jquery on the CDN
var jqueryCdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js";
bundles.Add(new ScriptBundle("~/bundles/jquery",jqueryCdnPath)
.Include("~/Scripts/jquery-{version}.js")
);
...
}
Upvotes: 2