简体   繁体   中英

ASP.NET MVC {version} wildcard in script bundle selects debug version?

I'm trying to use knockout.js imported from NuGet which includes knockout-3.2.0.js and knockout-3.2.0.debug.js . I add a new bundle like

bundles.Add(new ScriptBundle("~/bundles/knockout").Include(
    "~/Scripts/knockout-{version}.js"));

However when I inspect the webpage, it turns out that the loaded bundle is knockout-3.2.0.debug.js .

I read the following questions

  1. what is {version} in ScriptBundle("~/scripts/jquery-{version}.js")
  2. {version} wildcard in MVC4 Bundle

which seem not to be particularly helpful in answering my question.

It is because you have debug version of JS present in scripts folder.

If you look at other js there no debug file present so It will use jquery.1.7.0.js, but if you copy paste jquery.1.7.0.debug.js then it will choose that.

If you want knockout-3.2.0.js to be use then delete debug version of js.

You can also go to web.config

 <system.web>
    <compilation debug="false" targetFramework="4.0" />
    // set debug="true" or debug="false" 

if you set debug=true then debug version get selected or another version of js is selected if debug is false.

In Visual Studio you can have several Solution Configurations (it's a dropdown in the button vars under the Visual Studio main menu, by default in the Standard bar). By default, when you create a new project (or solution) you have 2 available configurations: Debug and Release. (You can acces to this also in the Build > Configuration Manager... menu).

When you build your solution or porject (or when you publish it) you must choose one of the configurations:

  • if you choose Debug, the project is compile with debug information, so that you can attach it to VS debugger and associate the running code with your source files. Besides there are some other things that happen, for example tha tthe bundler will use the debug version of JS files, instead of generating the minified bundle. The idea behind this is that, if you use this configuration, it's because you want to debug your code.

  • if you choose Release, the project is compiled without debug information. And the bundles use the normal or minified versions of the script, and each whole bundle is converted in a single, minified file

So, what you need to do is to choose the right configuration. Take into account that this affects both the js bundling, and the creation of assemblies. Sometimes the code in the assemblies can even have better performance because the release version will have some optimizations which are nos applied in the debug version of the assemblies, to allow debugging them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM