Reputation: 8477
When I create a new ASP.NET MVC Core targeting 2.1 RC1, it doesn't create the bundleconfig.json file which is used for bundling and minification. This file is created if I target 2.0.
Here is a example, the solution contains a new project targeting 2.0 and another targeting 2.1:
Has something replaced the builtin bundling and minification, or is this just a bug in RC1?
Upvotes: 33
Views: 17131
Reputation: 26813
bundleconfig.json was removed from the 2.1 templates because it relied on a tool not created or supported by Microsoft. See https://github.com/aspnet/templating/issues/326.
This file [bundleconfig.json] is for configuring the various incantations of the BundlerMinifier tool, which isn't actually shipped in the templates, or supported by Microsoft.
Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-magnification for details on configuring this project to bundle and minify static web assets.
Update May 2024 from Microsoft documentation Choose a bundling and minification strategy
ASP.NET Core is compatible with WebOptimizer, an open-source bundling and minification solution. For set up instructions and sample projects, see WebOptimizer. ASP.NET Core doesn't provide a native bundling and minification solution.
Third-party tools, such as Gulp and Webpack, provide workflow automation for bundling and minification, as well as linting and image optimization.
Advice May 2018: The ASP.NET Core team has replaced bundleconfig with "libman". Rightclick the project --> Add --> Client Side Library and add the packages you need
Upvotes: 30
Reputation: 17792
Also, as of 2021, please consider my answer on similar SO question here: https://stackoverflow.com/a/66659756/5101
TL;DR; - Use WebOptimizer Core nuget package, by Mads Kristensen, for .NET Core 3+ and .NET 5+
Upvotes: 3
Reputation: 1501
Note that this works for net core 2.2, not sure about 2.1. Also note that as of net core 3, it appears 'local tools' should (must?) be used instead: https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0#local-tools.
Finally had success configuring pre-build bundling using the (as of writing) recommended BundlerMinifier.Core
package.
Add the following to your .csproj file:
<!--
WARNING: don't update to latest version of BundlerMinifier.Core (as of 3.2.435)!
3.0.415 is the latest version that appears to work with this method of
automating bundling/minification
-->
<ItemGroup>
<PackageReference Include="BundlerMinifier.Core" Version="3.0.415" />
<DotNetCliToolReference Include="BundlerMinifier.Core" Version="3.0.415" />
</ItemGroup>
<Target Name="RestoreToolsAndBundle" BeforeTargets="Build">
<Exec Command="dotnet tool restore" />
<Exec Command="dotnet bundle" WorkingDirectory="$(ProjectDir)" />
</Target>
Note that this should be all that you need; you shouldn't need the 'Bundler & Minifier' VS extension, nor the 'BuildBundlerMinifier' package.
Attempt a build and you'll hopefully see in Output
that bundling and minification have completed, as per your bundleConfig.json
.
Upvotes: 4
Reputation: 395
I just installed Bundler and Minifier on my ASP.NET Core MVC project. When I right-clicked Bundler and Minifier > Bundle File, it made a bundleconfig.json
for me, which I could then set to bundle on each build. Publishing my web app to Azure sent the correct minified CSS and JS files.
One disadvantage is that you have to minify each file, which doesn't matter for me since I have 2, but I imagine most real projects will have many more than that.
Upvotes: 0
Reputation: 157
I had the same problem, I was able to copy over an existing bundle file into the project and that worked for me. You do need to follow this guidance and install the Bundle & Minifier extension … also, make sure you are using VS 15.7.
It does look like the bundle file is not included in the latest project template.
Upvotes: 7