Search code examples
asp.net-mvc-4embedded-resourcebundling-and-minification

Get js file as embeded resource from another assembly ASP,NET MVC4


 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)


Solution

  • 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")
        );
    
        ...
    }