目前我正在测试 bundle ,我知道可以使用 {version}
或 *
等通配符。我不完全确定 {version}
是干什么用的。我假设 *
像正则表达式一样工作,它接受所有匹配所有可能性的东西:jquery*
意味着像 jqueryA
、jquery-ui 这样的一切.js
等。我只是希望能够选择我的 javascript 库、css 文件等的开发版本或生产版本。以下是文件结构:
Content\
css\
bootstrap-theme.css
bootstrap-theme-min.css
bootstrap.css
bootstrap.min.css
the same with Scripts:
Scripts\
jquery-2.1.3.js
jquery-2.1.3.min.js
jquery-ui.js
jquery-ui.min.js
我已经定义了以下包,但我觉得 {version}
完全错误或在字符串中的错误位置:
bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include("~/Scripts/jquery-ui{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include("~/Scripts/modernizr-*"));
bundles.Add(new StyleBundle("~/bundles/css/Bootstrap").Include("~/Content/css/bootstrap-theme{version}.css"));
bundles.Add(new StyleBundle("~/bundles/css/Bootstrap").Include("~/Content/css/bootstrap{version}.css"));
bundles.Add(new StyleBundle("~/bundles/css").Include("~/Content/StyleSheet.css"));
我如何指示 ASP.NET 在应用程序的发布版本中用 bootstrap.css
代替 bootstrap.min.css
。
谢谢!
最佳答案
{version}
有点像通配符,但它做了两件额外的事情,它将通配符限制为看起来像版本号的东西(例如“1.2.3”)和它使用它找到的最高版本。这允许您拥有同一脚本的多个版本,并且 bundler 将始终使用最新版本。
例如,如果您有以下内容:
Scripts\
+ jquery-1.10.1.js
+ jquery-1.10.2.js
+ jquery-2.0.0.js
还有一个脚本包,例如:
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js");
然后,~/Scripts/jquery-2.0.0.js
将被添加到包中。
关于c# - 在 ASP.NET MVC 中定义一些包时对 {version} 感到困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28720820/