c# - 在 ASP.NET MVC 中定义一些包时对 {version} 感到困惑

标签 c# asp.net-mvc bundles

目前我正在测试 bundle ,我知道可以使用 {version}* 等通配符。我不完全确定 {version} 是干什么用的。我假设 * 像正则表达式一样工作,它接受所有匹配所有可能性的东西:jquery* 意味着像 jqueryAjquery-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/

相关文章:

c# - 远程属性在 MVC ASP.NET 中不起作用

c# - 我在哪里可以找到 System.Linq.Dynamic dll?

php - 如何在 symfony 2 中最好地构建应用程序

c# - 如何将Azure Mobile服务数据放入Asp.net(C#)中的 GridView 中?

c# - wpf 数据网格行中的小计单元格

asp.net-mvc - 'Controller' 是命名空间,但用作类型

c# - MVC4 _Layout.cshtml 脚本包

C# 使用约束泛型仅允许在父类型上运行函数

javascript - 使用naudio捕获音频并使用javascript播放

c - 保持 C 命令行应用程序在 Mac 应用程序包中运行