andrewdavey/cassette — Issue #121: Cassette does not properly include a bundle for one file
Author: kamranayub
Created: 2011-12-22 21:12:57+00:00
State: open

I ran into an issue that took me awhile to figure out (work around?).

Given this file structure:

```
Public
- Scripts
- Vendor
- jQuery-1.7.1.js
- App.js
```

I create bundles like this:

```c#
bundles.AddPerSubDirectory("Public/scripts");
```

There are two issues:

1. If I put in a reference inside App.js to "vendor" (the bundle), I get an exception that says the vendor path cannot be found.
2. If I try to reference the `public/scripts` folder in `_Layout.cshtml`, it will not include App.js

```
@{
Bundles.Reference("public/script/vendors");
Bundles.Reference("public/script");
}

// Farther down
@Bundles.RenderScripts()
```

Vendor files are included fine but App.js never gets included.

I have tried adding each folder manually, or simply removing vendors and only trying to create a bundle for App.js. No approach worked for me.

What ended up "fixing" the issue was just directly referencing App.js in the layout:

Bundles.Reference("public/scripts/app.js");

Then it properly included the file. I don't like this simply because now it will not auto-include any new JS files put into that folder.

Is there any code that says if a bundle contains 1 file, it can't be referenced like that (via parent folder)? I checked _cassette the entire time I ran into this problem, and it *was* detecting app.js and adding it to a bundle:

```
~/Public/scripts
app.js
```

Could it be how the folder structure is laid out? Maybe a path comparison or something is failing when it shouldn't be.

For issue 1 above, how are dependencies graphed? Sub-folders first, then top-level folder? Or top-level folder first, then sub-folders? If it's the latter, it's obvious why it failed on App.js (because Vendor bundle wasn't made yet). However, when I made the Vendor bundle first in the configuration, then the top-level-only (using a custom `FileSearch`), it still failed to find the vendor bundle. Not sure what's going on there.

I just wanted to document what happened to me. Things are working using the above workaround, although I still can't reference anything in app.js.