我在我的ASP.Net MVC 5项目中遇到了捆绑行为的奇怪问题。当我在BundleConfig.cs文件中显式声明所有文件时,我的项目运行得很好:
bundles.Add(new ScriptBundle("~/bundles/app").Include(
"~/app/app.js",
"~/app/config.js",
"~/app/dir1/file1.js",
"~/app/dir1/subdir1/file2.js",
.....
但是,如果我改用IncludeDirectory
,在开发期间(BundleTable.EnableOptimizations = false
)脚本路径不完整。以下是我看到的:
bundles.Add(new ScriptBundle("~/bundles/app").Include(
"~/app/app.js",
"~/app/config.js")
.IncludeDirectory("~/app/dir1", "*.js", true)
Chrome在尝试获取file2.js
时会显示404错误。捆绑系统将以下内容添加到我的布局页面:
<script src="/app/app.js"></script>
<script src="/app/config.js"></script>
<script src="/app/dir1/file1.js"></script>
<script src="/app/dir1/file2.js"></script>
路径 file2.js
不正确。它遗漏了路径中的 subdir1
部分。这里有什么我错过的吗?
subdir1
吗? - Curtis~/app/dir1
,它应该只包括该目录中立即的文件。如果它还包括子目录中的文件,而实际上没有将该子目录包含在路径中,那对我来说是新的问题。总的来说,在这里最好的做法是明确说明。如果您想要包括一个文件,请明确地包括该文件。像IncludeDirectory
这样的东西在我看来是危险的。 - Chris Pratt/app/dir1/subdir1/file2.js
中的代码也会缺失于该捆绑文件中。这并不会影响问题或可能的答案。 - Chris Pratt