我发布到天蓝色后,与MVC4的捆绑无法正常工作 [英] Bundling with MVC4 not working after I publish to azure

查看:59
本文介绍了我发布到天蓝色后,与MVC4的捆绑无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的应用程序捆绑我的脚本.我的调试工作正常,如果我使用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"));
        }
    }
}

未注释的行中断了调试版本

这是我称为"bundle"的布局

@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>

这是我的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>

当我在页面上使用CTRL + U检查捆绑的脚本时,这里是错误的链接 http://bat.azurewebsites.net/Content/MasterCss?v=htASNz4hgFAZTZ1JDW1D似乎与缩小有关.我已经阅读了一些教程,并在这里阅读了其他文章,但是他们的解决方案对我不起作用

小错误使我丧命,我将css捆绑为脚本捆绑包而不是样式捆绑包.

我已经做了很多尝试来解决此问题,包括设置源代码控制和构建配置.我的项目从被设置为使用git到tfs以及其他所有东西.

Hi I am trying to bundle my scripts for my application. My debug is working and if I publish with the Web.debug every thing works fine. But when I publish with the Web.releas my scripts don't load. Everything works locally it only stops when I publish to Azure from VS2012. Here is how I create my bundles.

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"));
        }
    }
}

The un-commented line breaks the debug build

This is my layout where I call the bundles

@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>

This is my 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>

Here is a link to the error when I check the bundled script with CTRL+U on the page http://bat.azurewebsites.net/Content/MasterCss?v=htASNz4hgFFA40tt0CVZdpwQudN8ZW4429UjRQZQJms1

It seems to be something to do with minification. I've followed some tutorials and have read other posts here but their solutions arn't working for me

解决方案

Small mistakes kill me, I was bundling my css as a script bundle not a style bundle.

I have done a lot to try fix this including setting up source control and build configurations. My project went from being set up to use git to tfs and everything.

这篇关于我发布到天蓝色后,与MVC4的捆绑无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆