Support including files that live outside of the app (i.e. VirtualDirectories)


(moved from http://aspnet.uservoice.com/forums/41199-general-asp-net/suggestions/2978724-use-virtual-file-system-for-asp-net-bundling-min)

Make ASP.NET Bundling & Minification (System.Web.Optimization) using the virtual file system to support bundling and minification of virtual files.
Closed Jun 3, 2013 at 11:03 PM by howarddierking
Fixed by the VPP feature of 1.1.0 - https://aspnetoptimization.codeplex.com/workitem/55 created to track the scenario of referencing resources outside an application's virtual path.


nabog wrote Sep 10, 2012 at 8:56 AM


I believe the main purpose of bundling is to support Javascript component development (i.e. instead of having all your code in a mammoth .js file, you can create components in separate files and let the bundling create the final .js file to be served to the browser).

In development environments that make heavy use of Javascript the component .js files are separated into multiple projects and/or folders in the Visual Studio solution.

The existing System.Web.Optimization.dll takes an uncomplicated view of the development environment, namely that all .js (and .css) files live in the single ASP.Net web project.

This is wrong. Complex development environments need to source .js files from multiple locations for testing and development. This is generally accomplished via virtual directories in IIS.

I hope the priority of this item can be raised, and we see the support for virtual directories released soon.


adamreeves wrote Sep 17, 2012 at 7:45 PM

I ran into this issue as well. I've put a good deal of effort in working around this, but I'd much appreciate the issue be fixed at the source.

Supporting virtual directory resolution would be simple if a Bundle retained virtual paths instead of converting to a FileInfo collection. By retaining a list of virtual paths, a call to IResolver.GetBundleContents could be non-destructive to virtual paths in debug mode. To work around this issue currently requires retrieving a list virtual directories, matching physical paths, and reconstructing the virtual path in a custom IResolver (which then loses the benefit of Bundle's internal BundleResponse cache process).

+1 to open-source this project soon.

vattimo51 wrote Oct 15, 2012 at 7:39 PM

Somewhat of a workaround:

When working with multiple ASP.NET web projects -- and creating a singular bundled JS file in Debug mode -- you will find (as alluded to here) that the assets are not all properly "expanded" -- in fact those not in the same ASP.NET project as the bundle are "lost"/"not emitted".

However, if you set:

BundleTable.EnableOptimizations = true;

but conditionally use Bundle vs ScriptBundle (or StyleBundle as desired):


return new Bundle(name);


return new ScriptBundle(name);

you can at least get bundling of all assets to occur w/o minification.

MrFoster78 wrote Nov 23, 2012 at 4:39 PM

Any idea when an updated nuget package will be available?

raspranav wrote Nov 24, 2012 at 11:32 PM

the updated nuget package is available as a pre release package http://nuget.org/packages/Microsoft.AspNet.web.optimization(1.1.0-alpha1)

MrFoster78 wrote Dec 6, 2012 at 3:19 PM


Thanks for the reply. I've tried the package you suggested and it does not seem to work for me.

I'm using MVC4 and registering it as follows:
    public static void RegisterBundles(BundleCollection bundles)
        bundles.Add(new StyleBundle("~/SiteStyles")
and then outputting to the page using


MrFoster78 wrote Dec 6, 2012 at 3:29 PM

My virtual path provider is being registered as follows:

            new ResourcePathProvider(new[]
                    Assembly.GetAssembly(typeof (TestPlugin.Models.SignInModel))
If the default path provider does not find the file on the local file system it checks any embedded resources.

flipdoubt wrote Dec 6, 2012 at 4:40 PM

I'm using the package from http://nuget.org/packages/Microsoft.AspNet.web.optimization(1.1.0-alpha1). If I debug my app in a root directory like http://localhost:53917, bundles render as expected. If I debug my app in a virtual directory named http://localhost:53917/dir, bundles do not render. This cannot be the correct behavior, can it?

After hearing so many good things about it, I'm shocked to find I cannot use the optimization framework in virtual directories. Disappointed that I wasted all this time delving into it, as I cannot use it until it does support virtual directories. How can this be marked fixed?!?

HaoK wrote Dec 6, 2012 at 8:51 PM

This issue was conflating the VPP change and specifically the Virtual Directory support. That is basically not supported currently as file contents outside of the app are not retrieved by the optimization framework currently. This scenario is similar to including references to external cdn/assets as the bundle would need to get the contents of the files via a different mechanism than the VirtualPathProvider, or at least have the ability to detect and get files from other VirtualDirectories.

flipdoubt wrote Dec 7, 2012 at 12:40 PM

@HaoK Are you saying my bundles should render when I run my app from http://localhost:53917/dir? They don't. Having <%= Scrips.Render("~/scripts/bundle") %> produces no output. If I simply change the URL by removing /dir in IIS Express, they render just fine.

flipdoubt wrote Dec 7, 2012 at 1:27 PM

MrFoster78 wrote Dec 7, 2012 at 6:31 PM


Are you saying that a change has been made to use a VirtualPathProvider? My simple test case shows that it is only reading files from the file system and not routing through the VPP. My issue has nothing to do with Virtual directories.

HaoK wrote Dec 10, 2012 at 5:52 PM

@MrFoster78 1.1-alpha1 should be using the VPP that is registered with HostingEnvironment.VirtualPathProvider by default now. You can specifically set a specfic one as well via BundleTable.Bundles as well

Giolvani wrote Jan 14, 2013 at 7:38 PM


I am too with this problem. I have a virtual directory that contains the content of another dir in IIS.
If i write
<pre><code> @Scripts.Render("~/bundles/scripts") </code></pre> nothing is displayed, but, if i write
<pre><code> <script src="@Scripts.Url("~/bundles/scripts")"></script> it is displayed but always minified </code></pre> Have any workarround to resolve it?


MrFoster78 wrote Jan 16, 2013 at 8:39 AM

After a bit more head scratching I discovered my problem was due to the virtual path provider being registered after the bundles were configured.

Works great now, thanks.