0

I'm trying to combine all scripts into one.. I have two folders, the main folder 'scripts' and the other 'scripts/other'.

When I try:

BundleTable.Bundles.Add(new ScriptBundle("~/scripts/all").Include("~/Scripts/*.js", "~/Scripts/other/*.js"));

scripts from 'scripts/other' are not included. but when I invert the order:

BundleTable.Bundles.Add(new ScriptBundle("~/scripts/all").Include("~/Scripts/other/*.js", "~/Scripts/*.js"));

it works!! Someone can tell me why?

4

2 回答 2

5

您可以尝试IncludeDirectory直接调用这些方法并查看是否看到相同的问题吗?

ScriptBundle("~/scripts/all").IncludeDirectory("~/Scripts", "*.js").IncludeDirectory("~/Scripts/other", "*.js"));

如果这可行,那么我们可能在这里有一个错误。

于 2012-06-15T23:07:15.553 回答
1

我不知道发生了什么,但这是 System.Web.Optimization.Bundle 中的代码:

// System.Web.Optimization.Bundle
public Bundle Include(params string[] virtualPaths)
{
    for (int i = 0; i < virtualPaths.Length; i++)
    {
        string text = virtualPaths[i];
        Exception ex = Bundle.ValidateVirtualPath(text, "virtualPaths");
        if (ex != null)
        {
            throw ex;
        }
        if (text.Contains('*'))
        {
            int num = text.LastIndexOf('/');
            string text2 = text.Substring(0, num);
            if (text2.Contains('*'))
            {
                throw new     ArgumentException(string.Format(CultureInfo.CurrentCulture,     OptimizationResources.InvalidPattern, new object[]
                {
                text
            }), "virtualPaths");
        }
        string text3 = "";
        if (num < text.Length - 1)
        {
            text3 = text.Substring(num + 1);
        }
        PatternType patternType = PatternHelper.GetPatternType(text3);
        ex = PatternHelper.ValidatePattern(patternType, text3, "virtualPaths");
        if (ex != null)
        {
            throw ex;
        }
        this.IncludeDirectory(text2, text3);
    }
    else
    {
        this.IncludeFile(text);
    }
}
return this;
}
于 2012-06-05T21:48:17.010 回答