IIS部署后样式绑定不工作(MVC 4) [英] Style bundling not working after IIS deployment (MVC 4)

查看:393
本文介绍了IIS部署后样式绑定不工作(MVC 4)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在部署到IIS后发现我的样式表出现问题。
我创建了一个简单的解决方案来演示我的问题。

I'm having troubles with my style sheets bundling after deployment to IIS. I've created a simple solution to demonstrate my problem.

我创建了一个简单的测试项目(VS 2012,MVC 4)以及一个包含Hello World字符串的视图。

I've created a simple test project (VS 2012, MVC 4) with a single controller and a view containing an "Hello World" string.

我通过简单的颜色更改在内容文件夹下创建了一个
$ b

I've created a (test) CSS under the content folder with simple simple color changing

Content\helloWorldCss\helloWorldStyle.css

然后,我编辑了我的 BundleConfig.cs 类,并将路径添加到我的CSS作为一个新的包:

Then, I've edited my BundleConfig.cs class and added the path to my CSS as a new bundle:

            bundles.Add(new StyleBundle("~/Content/helloWorldCss").Include("~/Content/helloWorldCss/helloWorldStyle.css"));

然后,我将新的包添加到 _Layout.cshtml

Then, I've added the new bundle to my the _Layout.cshtml:

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

当我通过VS(或Page inspector)运行我的应用程序时,我的CSS被成功应用,一切似乎都OK。但是,当我发布/部署我的项目到IIS(通过VS),我可以查看我的HTML,但我的CSS没有应用
部署后存在以下文件:

When I run my application via VS (or Page inspector) my CSS is being applied successfully and everything seems to be OK. However, when I publish/deploy my project to IIS (through VS), I can view my HTML but my CSS is not being applied. The following file exists after deployment:

Content\helloWorldCss\helloWorldStyle.css

真正让我困惑的是,当我改变我的_Layout.cshtml并添加一个正常ref到同一个CSS,

What really puzzles me is that when I alter my _Layout.cshtml and add a "regular" ref to the same CSS instead of using the bundle ref, the CSS is applied after publishing without any issues.

<link href="@Url.Content("~/Content/helloWorldCss/helloWorldStyle.css")" rel="stylesheet" type="text/css" />*

我将对此感到任何帮助和建议。

I will appreciate any help and advice on this.

推荐答案

我想你有一个名字碰撞这里。 ASP.NET MVC将在缩小后在 http://example.org/Content/helloWorldCss 上创建一个文件,并且已经有一个文件夹具有相同的路径。您可以在重命名您的包之后再次尝试吗?

I think you've got a name collision here. ASP.NET MVC will create a file on http://example.org/Content/helloWorldCss after minification and you already have a folder with the same path. Can you try it again after renaming your bundle?

BundleConfig.cs:

BundleConfig.cs:

bundles.Add(new StyleBundle("~/Content/helloWorld").Include("~/Content/helloWorldCss/helloWorldStyle.css"));

_Layout.cshtml:

_Layout.cshtml:

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

这篇关于IIS部署后样式绑定不工作(MVC 4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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