为什么我的CSS捆绑与垃圾箱的工作部署MVC4应用程序? [英] Why is my CSS bundling not working with a bin deployed MVC4 app?

查看:133
本文介绍了为什么我的CSS捆绑与垃圾箱的工作部署MVC4应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有斌部​​署的应用程序MVC4我的托管服务提供商的基础上,这里和一个或两个给出的即时修复建议,但最显而易见的问题是,对CSS的捆绑不起作用。当我更换明确的文件裁判捆绑裁判,我的CSS再次工作。

I have bin deployed an MVC4 application to my hosting provider, based on advice given here and one or two on-the-fly fixes, but the most immediately apparent problem is that the bundling for css doesn't work. When I replace the bundle ref with explicit file refs, my css works again.

我使用从VS2012标准MVC4 RTM项目模板。正在运行的提供商IIS 7.5和ASP.NET 4,我的$ P $同一应用程序的pvious MVC3版本工作得很好。我猜我已经抓住了某处过低版本的依赖,这可能也有助于我的<一个href=\"http://stackoverflow.com/questions/11531046/what-is-wrong-with-my-area-routing-in-my-bin-deployed-mvc4-app\">area基于操作链接问题。

I am using a standard MVC4 RTM project template from VS2012. The provider is running IIS 7.5 and ASP.NET 4, and my previous MVC3 version of the same app worked fine. I am guessing I have grabbed a dependency somewhere of too low a version, and this might also contribute to my area based action link problem.

技术的症状是:

@ Styles.Render(〜/内容/ CSS)呈现为&LT;链接HREF =/内容/ CSS? v =后面的rel =stylesheet属性/&GT;

推荐答案

如果.NET运行4.0或4.5的CSS和脚本捆绑应考虑工作。我运行.NET 4.0,它为我工作得很好。然而,为了获得微小和捆绑行为工作你的web.config必须设置不是在调试模式下运行。

The CSS and Script bundling should work regardless if .NET is running 4.0 or 4.5. I am running .NET 4.0 and it works fine for me. However in order to get the minification and bundling behavior to work your web.config must be set to not be running in debug mode.

<compilation debug="false" targetFramework="4.0">

拿这个包的jQuery UI例如,在_Layout.cshtml文件。

Take this bundle for jQuery UI example in the _Layout.cshtml file.

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

如果我跑调试=真正的我碰到下面的HTML。

If I run with debug="true" I get the following HTML.

<link href="/Content/themes/base/jquery.ui.core.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.resizable.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.selectable.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.accordion.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.autocomplete.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.button.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.dialog.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.slider.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.tabs.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.datepicker.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.progressbar.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.theme.css" rel="stylesheet"/>

但是,如果我用运行调试=false的。我会得到这个代替。

<link href="/Content/themes/base/css?v=myqT7npwmF2ABsuSaHqt8SCvK8UFWpRv7T4M8r3kiK01" rel="stylesheet"/>

这是一个功能,使您可以轻松地调试与你的脚本和CSS文件的问题。我使用的是MVC4 RTM。

This is a feature so you can easily debug problems with your Script and CSS files. I'm using the MVC4 RTM.

如果您认为这可能是一个MVC依赖问题,我建议你进入的NuGet和删除所有你的MVC相关软件包,然后搜索 Microsoft.AspNet.Mvc 包并安装它。我使用的是最新版本,它的未来是v.4.0.20710.0。这应该抓住你需要的所有依存关系。

If you think it might be an MVC dependency problem, I'd recommend going into Nuget and removing all of your MVC related packages, and then search for the Microsoft.AspNet.Mvc package and install it. I'm using the most recent version and it's coming up as v.4.0.20710.0. That should grab all the dependencies you need.

此外,如果你习惯使用MVC3,并正在试图用MVC4你要进入你的web.config(S)和更新其引用指向4.0版本的MVC。如果你不知道,你总是可以创造一个清新MVC4应用程序,并从那里复制web.config中。如果你不要忘记你的浏览/文件夹区域web.config中。

Also if you used to be using MVC3 and are now trying to use MVC4 you'll want to go into your web.config(s) and update their references to point to the 4.0 version of MVC. If you're not sure, you can always create a fresh MVC4 app and copy the web.config from there. Don't forget the web.config in your Views/Areas folders if you do.

更新:我发现,你需要有安装的NuGet包 Microsoft.AspNet.Web.Optimization 在您的项目。它在默认情况下在MVC4 RTM应用程序,如果你指定目标框架4.5或4.0包含不管。这是集束类都包含在名称空间,并没有出现依赖于该框架。我已经部署到没有安装4.5,它仍然工作正常,我的服务器。只要确保DLL被部署您的应用程序的其余部分。

UPDATE: I've found that what you need to have is the Nuget package Microsoft.AspNet.Web.Optimization installed in your project. It's included by default in an MVC4 RTM app regardless if you specify the target framework as 4.5 or 4.0. This is the namespace that the bundling classes are included in, and doesn't appear to be dependent on the framework. I've deployed to a server that does not have 4.5 installed and it still works as expected for me. Just make sure the DLL gets deployed with the rest of your app.

这篇关于为什么我的CSS捆绑与垃圾箱的工作部署MVC4应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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