简体   繁体   English

脚本包中的ASP.NET MVC {version}通配符选择调试版本吗?

[英]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 . 我正在尝试使用从NuGet导入的knockout-3.2.0.js ,其中包括knockout-3.2.0.jsknockout-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 . 但是,当我检查该网页时,发现装入的捆绑包是knockout-3.2.0.debug.js

I read the following questions 我阅读了以下问题

  1. what is {version} in ScriptBundle("~/scripts/jquery-{version}.js") ScriptBundle(“〜/ scripts / jquery- {version} .js”)中的{version}是什么
  2. {version} wildcard in MVC4 Bundle MVC4捆绑包中的{version}通配符

which seem not to be particularly helpful in answering my question. 这似乎对回答我的问题没有特别帮助。

It is because you have debug version of JS present in scripts folder. 这是因为脚本文件夹中存在JS的调试版本。

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. 如果查看其他js,则不存在调试文件,因此它将使用jquery.1.7.0.js,但是如果复制粘贴jquery.1.7.0.debug.js,则它将选择该文件。

If you want knockout-3.2.0.js to be use then delete debug version of js. 如果要使用淘汰赛3.2.0.js,请删除js的调试版本。

You can also go to web.config 您也可以转到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. 如果设置debug = true,则选择debug version;如果debug为false,则选择其他版本的js。

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). 在Visual Studio中,您可以具有多个解决方案配置(默认情况下,在Standard栏中,这是Visual Studio主菜单下的vars按钮的下拉列表)。 By default, when you create a new project (or solution) you have 2 available configurations: Debug and Release. 默认情况下,在创建新项目(或解决方案)时,您有2种可用配置:调试和发布。 (You can acces to this also in the Build > Configuration Manager... menu). (您也可以在Build> Configuration Manager ...菜单中访问此权限)。

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. 如果选择“调试”,则将使用调试信息编译项目,以便可以将其附加到VS调试器,并将运行的代码与源文件相关联。 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. 除此之外,还会发生其他一些事情,例如,捆绑程序将使用JS文件的调试版本,而不是生成缩小的捆绑程序。 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. 考虑到这会影响js捆绑和程序集的创建。 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. 有时,程序集中的代码甚至可以具有更好的性能,因为发行版将进行一些优化,这些优化在程序集的调试版本中没有应用,以允许对其进行调试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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