Has something replaced bundleconfig.json in ASP.NET Core MVC 2.1?

冷暖自知 提交于 2020-01-23 04:15:13

问题


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?


回答1:


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.

The ASP.NET Core team is considering replacing this with "libman", which is going to be a supported Visual Studio feature. This work isn't done yet, though. See https://github.com/aspnet/templating/issues/471




回答2:


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.




回答3:


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.




回答4:


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://docs.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.



来源:https://stackoverflow.com/questions/50419033/has-something-replaced-bundleconfig-json-in-asp-net-core-mvc-2-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!