与.net绑定和缩小会丢失CSS中的图像引用
我意识到这是通过网络提出的,但我似乎找不到解决这个问题的确切答案 这就是我们捆绑销售的方式与.net绑定和缩小会丢失CSS中的图像引用,.net,asp.net-mvc,asp.net-mvc-4,bundling-and-minification,.net,Asp.net Mvc,Asp.net Mvc 4,Bundling And Minification,我意识到这是通过网络提出的,但我似乎找不到解决这个问题的确切答案 这就是我们捆绑销售的方式 // iPortal Specific bundles.Add(new StyleBundle("~/bundles/css/MyCSS") .Include("~/Content/css/MyCSS.css") .Include("~/Content/css/MyCSSMedia.css")); 然后在_布局页面内:- @Styles.Render
// iPortal Specific
bundles.Add(new StyleBundle("~/bundles/css/MyCSS")
.Include("~/Content/css/MyCSS.css")
.Include("~/Content/css/MyCSSMedia.css"));
然后在_布局页面内:-
@Styles.Render("~/bundles/css/MyCSS")
其中~bundles/css/MyCSS是一个虚拟目录,因为它不存在于服务器上
我们的CSS结构是:-
Content
CSS
MyCSS.css
_Images
其中MyCSS.css引用_images文件夹中的图像
我们已经尝试使用
.Include("~/Content/css/MyCSS.css", new CssRewriteUrlTransform())
这没用
也试过了
public class CssRewriteUrlTransformWrapper : IItemTransform
{
public string Process(string includedVirtualPath, string input)
{
return new CssRewriteUrlTransform().Process("~" + VirtualPathUtility.ToAbsolute(includedVirtualPath), input);
}
}
再说一次,这没用
我们发现的另一个解决方案是改变虚拟目录以匹配物理目录,这感觉不太对
我们遗漏了什么吗?我认为,当您在html中提取生成的css文件时,它看起来是这样的: 捆绑包/css 图像处于以下状态时: 内容/图像 CSS指向bundles/\u图像,这显然是不存在的 我认为你有两个选择: 将图像移动到顶层,这样您的CSS就可以指向那里,这两者都可以捆绑使用,也可以不捆绑使用 将CSSRWriteUrlTransferorMwrapper中CSS中的图像路径替换为../Content/\u图像
谢谢,这将适用于这个特定的文件,但是,我们也在使用bootstrap和font-awesome,由于您提到它正在查看bundles/xxxx中嵌入的任何内容,因此我们遇到了相同的问题