【问题标题】:ASP.NET MVC 4 bundle with wildcard in folder path文件夹路径中带有通配符的 ASP.NET MVC 4 捆绑包
【发布时间】:2013-08-24 11:28:42
【问题描述】:

我的团队使用自定义 NuGet 包来安装 jQuery UI,它将主题文件放入如下目录结构中:

  • 内容
    • jquery-ui-1.10.3
      • 图片
      • jquery-ui.css
      • jquery-ui.min.css

我正在尝试使用 ASP.NET MVC 4 捆绑包将此内容包含在我的应用程序的 App_Start 文件夹内的 BundleConfig 类中,如下所示:

bundles.Add( new StyleBundle( "~/bundles/css" )
                 .Include( "~/Content/normalize-{version}.css",
                           "~/Content/jquery-ui-{version}/jquery-ui.css",
                           "~/Content/Site.css" ) );

这会在我运行网站时引发错误:

Directory does not exist.
Parameter name: directoryVirtualPath

我也试过了:

bundles.Add( new StyleBundle( "~/bundles/css" )
                 .Include( "~/Content/normalize-{version}.css" )
                 .IncludeDirectory( "~/Content/jquery-ui-*", "*.css" )
                 .Include( "~/Content/Site.css" ) );

这也不起作用(显然)。我可以明确指定文件夹上的版本,但这会破坏使用捆绑包的部分好处。

那么如何在文件夹路径中使用通配符呢?

【问题讨论】:

    标签: asp.net-mvc jquery-ui asp.net-mvc-4 bundle


    【解决方案1】:

    您可以使用搜索子目录的IncludeDirectory 的重载版本。

    假设你有以下文件:

    \Root\Content\jquery-ui-1.10.3\jquery-ui.css

    使用此代码查找并添加它:

    .IncludeDirectory("~/Content", "jquery-ui.css", true)
    

    这很有用,因为它总能找到jquery-ui.css,不管你把它放在哪里。

    这种方法的缺点是它会搜索并包含它找到的所有 jquery-ui.css 文件,如果您不能确保只存在一个jquery-ui.css,这可能会导致一些错误.

    (记住搜索子目录也会搜索根目录,即~/Content)

    【讨论】:

    • 所以没有其他选项可以指定所需的文件名而不是包括所有 ??
    猜你喜欢
    • 1970-01-01
    • 2015-08-07
    • 2021-11-16
    • 2014-06-30
    • 2013-08-06
    • 2023-04-06
    • 2015-09-12
    • 1970-01-01
    • 2014-11-06
    相关资源
    最近更新 更多