Style Styles in .NET 4.5 and Icons in CSS

I am starting to use .NET 4.5, which is built into minification and union to minimize and combine my CSS and JavaScript. JavaScript minimization works great, however, I ran into the problem of minimizing CSS. I am creating a style set using the code below -

var myCss = new string[] { "~/Content/jquery.css", "~/Content/app.css", }; bundles.Add(new StyleBundle("~/bundles/MySiteCss/").Include(myCss )); 

and then I refer to them in a .cshtml (razor file) as shown below -

 @Styles.Render("~/bundles/MySiteCss/") 

It minimizes the CSS file. However, if the CSS files contain styles containing help links, such as background-image: url ('img / icon.png'), it tries to load this icon file from a new location (obtained from the package name) = / bundles / MySiteCss / img / icon.png

Since the icon does not exist in the location, it does not load and does not appear on the page.

+8
asp.net-mvc minify asp.net-optimization bundling-and-minification
source share
2 answers

You need your packages and CSS to serve from the same place for this to work easily. For example, change the line of your package:

 bundles.Add(new StyleBundle("~/Content/MySiteCss/").Include(myCss)); 

And update your link:

 @Styles.Render("~/Content/MySiteCss/") 
+10
source share

This has been fixed in version 1.1.0-alpha1 of the Microsoft ASP.NET Web Optimization Framework.
You can get the update through NuGet ( https://nuget.org/packages/Microsoft.AspNet.Web.Optimization ) if you enable Prerelease.

0
source share

All Articles