Script Bundling doesn't work for SignalR Release Candidates

Posted on Posted in Uncategorized

With Sig­nalR now avail­able as a Release Can­di­date from Microsoft, we found that our script bundling no longer worked.  Our Bundle­Con­fig con­tained a state­ment to reg­is­ter the bun­dle and include the ver­sion-based file.

bundles.Add(new Script­Bun­dle("~/bundles/signalr").Include(
            "~/Scripts/jquery.signalR-{version}.js"));

Once upgrad­ing from 0.5.3 to 1.0.0-rc2 via NuGet, the bun­dle request returned an emp­ty response.  Down­grad­ing back to 0.5.3 fixed the issue and our bun­dle request returned as expected.

Hard­cod­ing the entry by replac­ing "{ver­sion}" with "1.0.0-rc2" also resolved the issue, so the {ver­sion} pars­ing was not work­ing for some rea­son.  Pre­sum­ably, {ver­sion} was sup­posed to be replaced with the installed ver­sion of the prod­uct dur­ing bundling.  A check of packages.config showed that the ver­sion for Sig­nalR was cor­rect­ly set to "1.0.0-rc2".

It turns out that {ver­sion}, rather than being replaced with the installed ver­sion num­ber, is sim­ply a regex match­ing pat­tern for ver­sion num­bers in a for­mat sim­i­lar to #.#.#.  It does not look for a par­tic­u­lar ver­sion num­ber, but rather any­thing that looks like a ver­sion num­ber.  In this case, it is get­ting tripped up on the "-rc2" in the script name.  You can work around this with­out break­ing future (non-Pre­re­lease) upgrades by adding the fol­low­ing to Script­Bun­dle configuration.

bundles.Add(new Script­Bun­dle("~/bundles/signalr").Include(
            "~/Scripts/jquery.signalR-{version}.js",
            "~/Scripts/jquery.signalR-1.0.0-rc2.js"));

It's not the most dynam­ic solu­tion, but it does allow bundling to imme­di­ate­ly work with any upgrades.  The only caveat would be what if upgrad­ing to a dif­fer­ent Pre­re­lease ver­sion (rc3, for exam­ple), an update to the con­fig would be required.  While there is wild­card (*) sup­port, Microsoft advis­es against using it in most cas­es, pre­fer­ring that scripts be hard­cod­ed.  So for now, this is prob­a­bly the least painful solution.

Leave a Reply

Your email address will not be published. Required fields are marked *