Writing
← Writing

Move your MVC 5 bundles to ASP.NET Core without changing a single URL

If you maintain an ASP.NET MVC 5 app, its CSS and JavaScript probably go through System.Web.Optimization:

bundles.Add(new ScriptBundle("~/bundles/jquery")
    .Include("~/Scripts/jquery-{version}.js"));
bundles.Add(new StyleBundle("~/Content/css")
    .Include("~/Content/bootstrap.css", "~/Content/site.css"));
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/jquery")

That package has two problems today.

It doesn’t exist on ASP.NET Core. Moving the app means replacing every bundle, usually with a build step or a different runtime bundler, and the bundle URLs (/bundles/jquery, /Content/css) change on the way. Anything that requested them, from cached pages to other sites to monitoring, breaks.

It still minifies with WebGrease. WebGrease is long abandoned and fails on modern syntax. In a side-by-side run it rejected a stylesheet using custom properties, clamp() and :is(), and threw on a script using arrow functions, ?. and ??. NUglify minified both.

same registration, same URL, both frameworks

DragonBundles is a bundler for both. A bundle named by a path is served at exactly that path, on .NET Framework and on ASP.NET Core:

Classic ASP.NET:

App_Start/BundleConfig.cs
bundles.AddScriptBundle(
    "~/bundles/jquery", "~/Scripts/jquery-3.7.1.js");
Views/Shared/_Layout.cshtml
@Html.ScriptBundle("~/bundles/jquery")

ASP.NET Core:

Program.cs
app.UseBundling(b => b.AddScriptBundle(
    "~/bundles/jquery", "~/Scripts/jquery-3.7.1.js"));
Views/Shared/_Layout.cshtml
<script-bundle name="~/bundles/jquery" />

Both serve /bundles/jquery?v=…, minified with NUglify, with a Subresource Integrity hash on the tag and a source map at /bundles/jquery.map. So you can switch the legacy app to DragonBundles first, deploy, and check that nothing changed. Then you move to ASP.NET Core with the same file lists and the same URLs. If you also want identical markup, two options drop the extra attributes so the tags are exactly what Styles.Render and Scripts.Render emitted.

three System.Web behaviours that bite during a migration

Building this meant testing against the real System.Web pipeline: the actual System.Web.Optimization handler, with views compiled at runtime. Three behaviours came out of that, each now pinned by a test, and each one changes what a browser receives:

  1. System.Web reorders your files. With optimizations on, BundleCollection.FileSetOrderList moves files such as jquery*, modernizr*, reset.css and normalize.css to the front, whatever order you listed them in. ASP.NET Core bundlers use the listed order, so a script that depends on order can break only after the move. DragonBundles has an opt-in PreserveFileOrder so the legacy app serves the listed order first. (test)
  2. It serves x.min.js when you listed x.js. In release mode, a listed file with a .min sibling is served from the sibling (FileExtensionReplacementList). Know which file you were actually shipping before you copy the list.
  3. CssRewriteUrlTransform ignores virtual directories. Under an IIS application at /myapp, it rewrites url(../img/logo.svg) to /Content/img/logo.svg, missing the /myapp and so returning a 404. DragonBundles writes CSS urls relative to the bundle instead, on both frameworks, so they work under any virtual directory or PathBase.

when to use something else

DragonBundles is for an app that runs on System.Web today and is moving, or may move, to ASP.NET Core. Other tools fit other cases:

  • A new ASP.NET Core app: WebOptimizer and Smidge are established runtime bundlers for ASP.NET Core, and Smidge released 5.1.0 in November 2026. Bundling (Karambolo.AspNetCore.Bundling) was built as a .NET Core replacement for System.Web.Optimization, with a similar API, and released 3.10.3 in November 2026. All three run on ASP.NET Core only, so none of them can serve the legacy app while it is still on System.Web.
  • Bundling at build time: BundlerMinifier writes bundled files during the build and also works in .NET Framework projects. Its last NuGet release was 3.2.449, in June 2020.
  • A frontend with a node toolchain: Vite or esbuild do far more than any of these (modules, TypeScript, tree shaking). They write static files at build time (Vite adds a content hash to file names by default), so keeping the old extensionless bundle URLs such as /bundles/jquery takes extra routing.

If your app has no System.Web history, any of those is a fine choice.

how it’s checked

Every commit runs the MVC 5 sample in IIS (integrated pipeline, at a site root and under a virtual directory) and the ASP.NET Core sample on Kestrel (at a root and under a PathBase). Headless Chromium then checks each one:

  • SRI is accepted;
  • the CSS applies and the scripts run;
  • source maps resolve the way devtools resolves them;
  • both apps serve every bundle at the same path.

The migration walkthrough is built on those two samples.

try it

dotnet add package DragonBundles

Issues and questions are welcome on GitHub.

Nothing matches β€œβ€

↑↓ move ↡ select ⌘K toggle