我正在MVC4中实现捆绑和缩小支持并进行设置,以便它可以自动编译我的Bootstrap .less文件.我在BundleConfig.cs文件中有以下代码
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
// base bundles that come with MVC 4
var bootstrapBundle = new Bundle("~/bundles/bootstrap").Include("~/Content/less/bootstrap.less");
bootstrapBundle.Transforms.Add(new TwitterBootstrapLessTransform());
bootstrapBundle.Transforms.Add(new CssMinify());
bundles.Add(bootstrapBundle);
}
}
Run Code Online (Sandbox Code Playgroud)
TwitterBootsrapLessTransform如下所示(由于需要将sub .less文件导入dotLess,因此比我想要的更复杂)
public class TwitterBootstrapLessTransform : IBundleTransform
{
public static string BundlePath { get; private set; }
public void Process(BundleContext context, BundleResponse response)
{
setBasePath(context);
var config = new DotlessConfiguration(DotlessConfiguration.GetDefault());
config.LessSource = typeof(TwitterBootstrapLessMinifyBundleFileReader);
response.Content = Less.Parse(response.Content, config);
response.ContentType = "text/css";
}
private void setBasePath(BundleContext context)
{
BundlePath = …Run Code Online (Sandbox Code Playgroud) asp.net-mvc-4 bundling-and-minification asp.net-optimization
我有一个带有MEF和RavenBD的asp.net MVC 4项目.
当项目加载时,它会抛出此异常:无法加载文件或程序集Antlr3.Runtime.dll
我发现RavenDB和WebGrease(与MVC 4一起安装)都使用Antlr3.但WebGrease附带了自己的Antlr3 dll,由微软签署 - PublicKeyToken 31bf3856ad364e35
Antlr3默认的PublicKeyToken是eb42632606e9261f.
RavenDB和WebGrease使用相同版本的Antlr3 3.3.1.7705
我该如何解决这个问题?
bundle antlr3 asp.net-mvc-4 bundling-and-minification asp.net-optimization
这个问题有很多解决方案,请阅读下面的所有答案,它们也可以帮助您解决问题.如果您找到解决此问题的新方法,请在答案中记录
我试图将System.Web.Optimization添加到我的ASP.NET Web窗体解决方案.我通过NuGet包添加了Microsoft ASP.NET Web Optimization Framework.它将Microsoft.Web.Infrastracture和WebGrease(1.5.2)添加到引用中.
但是,当我跑
<%= System.Web.Optimization.Scripts.Render("~/bundles/js")%>
Run Code Online (Sandbox Code Playgroud)
我得到运行时错误
Could not load file or assembly 'WebGrease, Version=1.5.1.25624, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Run Code Online (Sandbox Code Playgroud)
我已经尝试将assemblyBinding添加到Web.Config
<runtime>
<legacyUnhandledExceptionPolicy enabled="1"/>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.5.1.25624" newVersion="1.5.2.14234"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
Run Code Online (Sandbox Code Playgroud)
但没有任何运气.
我注意到我的WebSite的Web配置包含这一行
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
Run Code Online (Sandbox Code Playgroud)
如果我用它替换它
<configuration>
Run Code Online (Sandbox Code Playgroud)
然后一切正常,我没有得到运行时错误.不幸的是,我需要xmlns.我项目的其他组件依赖于它.
为什么当架构指向v2.0时,Optimization会尝试加载旧版本?有没有办法强制它加载最新或唯一可用的WebGrease.dll?
如果不改变,我还能尝试什么
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> ?
Run Code Online (Sandbox Code Playgroud)
感谢您提供任何帮助!
编辑:1)附加FusionLog结果.也许它会有所帮助
=== Pre-bind state information ===
LOG: User = …Run Code Online (Sandbox Code Playgroud) c# asp.net asp.net-mvc bundling-and-minification asp.net-optimization
我只是尝试ASP.NET MVC 4,但我无法弄清楚如何禁用Javascript/CSS缩小功能.特别是对于开发环境,这将有助于调试.我想这将是web.config中的一个开关,但由于ASP.NET MVC 4目前仍处于测试阶段,因此实际上没有太多信息.如果有人可以帮助或指向正确的博客文章等,将不胜感激.
生成的捆绑文件放在哪里?
bundles.Add(new ScriptBundle("~/bundles/jqueryall")
.IncludeDirectory("~/scripts/", "*.js", true)
Run Code Online (Sandbox Code Playgroud) asp.net-mvc-4 bundling-and-minification asp.net-optimization
我试图弄清楚为什么当我创建一个脚本包引用我的主站点的应用程序文件夹下的IIS VirtualDirectory中的文件时,为什么它不会输出任何内容.
我发现这篇文章:
为什么ResolveBundleUrl不适用于自定义文件夹?(MVC Beta 4)
但是对于System.Web.Optimization的最新beta版本,它似乎不再有效.
我想定义一个这样的包:
bundles.Add(
new StyleBundle("~/style.css").Include(
//...
));
Run Code Online (Sandbox Code Playgroud)
如果捆绑包名称只是"~/style"这样,但是文件扩展名它总是返回404.我怀疑服务器在驱动器上搜索CSS和JS文件并忽略捆绑系统,但是我找不到其他人正在尝试在包名称中包含文件扩展名.这可能没有像URL重写这样的东西吗?
asp.net-mvc asp.net-mvc-4 bundling-and-minification asp.net-optimization
我正在尝试渲染一组css文件,但输出顺序错误.我已经尝试过解决方案@ MVC4 Beta Minification and Bundling:在浏览器中订购文件和调试,但它没有帮助.这是捆绑:
bundles.Add(new StyleBundle("~/stylesheet")
.Include("~/css/main.css")
.Include("~/css/mvc.css")
.Include("~/js/jquery.thickbox.css")
.Include("~/js/jquery.rating.css")
.Include("~/css/ProductListing.css")
.Include("~/css/dropdown/dropdown.css")
.Include("~/css/dropdown/dropdown.vertical.css")
.Include("~/js/fancybox/jquery.fancybox-1.3.1.css")
.Include("~/css/scartpopup.css")
.Include("~/css/ShoppingCart.css")
.Include("~/css/ceebox.css")
.Include("~/css/tooltip.css")
.Include("~/css/recent_blog_posts.css")
.Include("~/css/ProductDetail.css")
.Include("~/css/jquery-ui-1.7.3.custom.css")
.Include("~/css/filter_box.css")
.Include("~/css/custom_page.css")
.Include("~/css/Checkout.css")
.Include("~/css/CheckoutButton.css")
);
Run Code Online (Sandbox Code Playgroud)
这是结果,你可以看到jquery-ui到顶部.
<link href="/css/jquery-ui-1.7.3.custom.css" rel="stylesheet"/>
<link href="/css/main.css" rel="stylesheet"/>
<link href="/css/mvc.css" rel="stylesheet"/>
<link href="/js/jquery.thickbox.css" rel="stylesheet"/>
<link href="/js/jquery.rating.css" rel="stylesheet"/>
<link href="/css/ProductListing.css" rel="stylesheet"/>
<link href="/css/dropdown/dropdown.css" rel="stylesheet"/>
<link href="/css/dropdown/dropdown.vertical.css" rel="stylesheet"/>
<link href="/js/fancybox/jquery.fancybox-1.3.1.css" rel="stylesheet"/>
<link href="/css/scartpopup.css" rel="stylesheet"/>
<link href="/css/ShoppingCart.css" rel="stylesheet"/>
<link href="/css/ceebox.css" rel="stylesheet"/>
<link href="/css/tooltip.css" rel="stylesheet"/>
<link href="/css/recent_blog_posts.css" rel="stylesheet"/>
<link href="/css/ProductDetail.css" rel="stylesheet"/>
<link href="/css/filter_box.css" rel="stylesheet"/>
<link href="/css/custom_page.css" …Run Code Online (Sandbox Code Playgroud) 每次部署MVC Web应用程序时,我的服务器都必须重新缓存所有js和css包.
因此,部署后第一个视图渲染可能需要几秒钟.
有没有办法预先缓存包?毕竟,文件在编译时是静态的.
我已经开始使用MVC4 Beta中包含的捆绑和缩小功能.我遇到了一些问题:
首先,如果我使用经典<script src="Folder/js" type="text/javascript"/>捆绑,似乎我必须重命名我的文件,以确保它们以正确的顺序捆绑.
我遇到的下一个问题是调试.我喜欢在我的测试浏览器中单步执行javascript,有没有办法在DEBUG模式下关闭缩小?
编辑:要清楚,我知道我可以创建捆绑包并从C#注册它们,只是看起来真的很丑陋.