【问题标题】:Azure release build not showing bundlesAzure 发布版本未显示捆绑包
【发布时间】:2015-05-24 03:58:55
【问题描述】:

当我将调试版本发布到 Azure 上时...我的所有样式文件都可以访问。

当我将我的发布版本发布到 Azure 上时...我的样式文件都无法访问。

You do not have permission to view this directory or page.

在我的代码中,我有这样的包:

        bundles.Add(new StyleBundle("~/Content/css").Include(
                  "~/Content/Packages/Bootstrap/src/bootstrap.css",
                  "~/Content/CSS/site.css",
                  "~/Content/CSS/bootstrap-theme-conflicts.css" ) );

在我看来,我有这个:

@Styles.Render( "~/Content/css" )

我的 Content 文件夹结构是:

已发布应用程序中的结束 url 为:

azurewebsites.net/Content/css/?v=i2nuaUMdmGVopZ-yRx75EKwl3vXByH5xgX4-uk0R9oE1

如果我直接进入文件...即:

azurewebsites.net/Content/CSS/Site.css

他们很好。

有用的资源:

Bootstrap icons are loaded locally but not when online

【问题讨论】:

    标签: azure asp.net-mvc-5 bundle


    【解决方案1】:

    包名必须代表一个真实的文件目录+ 1级...所以我添加了我的目录,然后在末尾添加了单词文件。单词文件然后成为文件名!

    因此,对于我的示例,我必须拆分捆绑包:

            bundles.Add(new StyleBundle("~/bundle/Packages/Bootstrap/src/files").Include(
                      "~/Content/Packages/Bootstrap/src/bootstrap.css"));
    
            bundles.Add(new StyleBundle("~/bundle/CSS/files").Include(
                      "~/Content/CSS/site.css",
                      "~/Content/CSS/bootstrap-theme-conflicts.css"));
    

    然后在我的剃刀观点中,我将我的更改为:

    @Styles.Render("~/Content/Packages/Bootstrap/src/files")
    @Styles.Render("~/Content/CSS/files")
    

    【讨论】:

    • 终于到了:)
    • 如果你在做@Styles.Render("~/Content/CSS/files") 你实际上并没有使用捆绑包......
    【解决方案2】:

    我在 Azure 网站中部署代码时遇到了这个问题。当我从 visualstudio.com 部署构建时它确实有效,而当我尝试从 Visual Studio 2013 发布构建时却没有。主要问题是 CSS 缩小。我完全同意对这个问题的第一个回答。但想到分享对我有用的解决方案,可能会帮助您修复它。

    基本上,当我们通过 VSO 部署时,它会通过启动 system.web.Optimization 为 css、js 生成缩小文件,但是当我们从 VS 2013 发布构建时,我们必须注意以下事项。 bundling-and-minification 1. 确保文件夹结构和你的打包器命名约定应该不同。像这样的。

    bundles.Add(new StyleBundle("~/Content/materialize/mcss").Include(
                      "~/Content//materialize/css/materialize.css"));
    

    2。在你的 bundleconfig 定义的底部添加

    public static void RegisterBundles(BundleCollection bundles)
    {
      bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                 "~/Scripts/jquery-{version}.js"));
    
       // Code removed for clarity.
       BundleTable.EnableOptimizations = true;
    }
    

    3。确保在 web.config 中添加 debug false (当您开始本地调试时,VS2013 会弹出一个提示,说您需要确保在部署到 prod 之前将其放回原处。这本身就说明了很多。

    <system.web>
      <compilation debug="true" />
      <!-- Lines removed for clarity. -->
    </system.web>
    

    更多信息-why-is-my-css-bundling-not-working-with-a-bin-deployed-mvc4-app

    【讨论】:

      【解决方案3】:

      我的包源位于本地目录 ~/node_modules。 这个目录不是我项目的一部分,但是在解决方案资源管理器中选择“显示所有文件”后,我可以看到它。然后右键单击它并选择“Publish node_modules”选项就足够了。

      【讨论】:

        【解决方案4】:

        在您的代码中如下

        bundles.Add(new StyleBundle("~/Content/css")

        您需要添加“捆绑包”来代替内容,以便您的代码如下所示:

        bundles.Add(new StyleBundle("~/Content/css")

        【讨论】:

        • `先生。戴夫克拉克的以下陈述是正确的。如果你正在做 @Styles.Render("~/Content/CSS/files") 你实际上并没有使用捆绑包... – Dave Clarke 2017-04-25 14:58:58
        猜你喜欢
        • 1970-01-01
        • 2016-03-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-28
        • 2015-07-07
        • 2016-12-09
        • 1970-01-01
        相关资源
        最近更新 更多