在我发布到azure之后,捆绑MVC4无法正常工作

Jef*_*inn 10 bundle azure asp.net-mvc-4

嗨,我想为我的应用程序捆绑我的脚本.我的调试工作正常,如果我使用Web.debug发布,一切正常.但是当我使用Web.releas发布时,我的脚本不会加载.一切都在本地工作,只有当我从VS2012发布到Azure时才会停止.以下是我创建捆绑包的方法.

namespace BAT.App_Start
{
  public class BundleConfig
  {
    public static void RegisterBundles(BundleCollection bundles)
    {
        //BundleTable.EnableOptimizations = true;

        bundles.Add(new ScriptBundle("~/Content/MasterCss")
                .Include("~/Content/bootstrap.css")
                .Include("~/Content/bootstrap-responsive.css")
                .Include("~/Content/CSS/site.css"));

        bundles.Add(new ScriptBundle("~/Scripts/MasterScripts")
                .Include("~/Scripts/jquery-{version}.js")
                .Include("~/Scripts/bootstrap.js"));

        bundles.Add(new ScriptBundle("~/Scripts/Validation")
                .Include("~/Scripts/jquery.validate.js")
                .Include("~/Scripts/jquery.validate.unobtrusive.js"));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

未注释的行打破了调试版本

这是我调用捆绑包的布局

@using System.Web.Optimization
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title Business Analysis Tool </title>

    @Styles.Render("~/Content/MasterCss")
</head>

<body>
    <div class="container-fluid">
        <div class="row-fluid"> @RenderPage("~/Views/Shared/_Header.cshtml") </div>
        <div class="row-fluid"> @RenderBody() </div>
        <div class="row-fluid"> @RenderPage("~/Views/Shared/_Footer.cshtml") </div>
    </div>
    @Scripts.Render("~/Scripts/MasterScripts")    
    @RenderSection("scriptholder", false)
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

这是我的Release.Config

<?xml version="1.0"?>
    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
    <system.web>
        <compilation xdt:Transform="RemoveAttributes(debug)" />
    </system.web>
    </configuration>
Run Code Online (Sandbox Code Playgroud)

当我在页面上用CTRL + U检查捆绑脚本时,这是一个错误的链接 http://bat.azurewebsites.net/Content/MasterCss?v=htASNz4hgFFA40tt0CVZdpwQudN8ZW4429UjRQZQJms1

这似乎与缩小有关.我已经按照一些教程阅读了其他帖子,但他们的解决方案并不适用于我

Ale*_*ens 5

这个真的很简单:

我有以下内容:

bundles.Add(new StyleBundle("~/Content/css").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/site.css"));
Run Code Online (Sandbox Code Playgroud)

我的解决方案中还有一个文件夹:

/Content/Css
Run Code Online (Sandbox Code Playgroud)

这就是问题所在,stylebundle与我的解决方案中的文件夹同名.

将stylebundle重命名为:

 bundles.Add(new StyleBundle("~/scripts/css").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/site.css"));
Run Code Online (Sandbox Code Playgroud)

并且(记住)改变你引用它的位置,_Layout.cshmtl

因此,为了清楚说明,如果您的样式名称与解决方案中的实际文件夹相同,那么您将会遇到此问题.简单地命名它不同的东西.


Jef*_*inn 4

小错误杀了我,我将我的 css 捆绑为脚本包而不是样式包。

我已经做了很多尝试解决这个问题,包括设置源代码管理和构建配置。我的项目从使用 git 到使用 tfs 等等。