问题描述
我试图使用新功能捆绑在一个项目中,我最近从MVC 3转换为MVC 4测试版。它需要一条线在Global.asax中code的, BundleTable.Bundles.RegisterTemplateBundles();
,要求使用System.Web.Optimization ;
上方
I'm trying to use the new bundling feature in a project I recently converted from MVC 3 to MVC 4 beta. It requires a line of code in global.asax, BundleTable.Bundles.RegisterTemplateBundles();
, which requires using System.Web.Optimization;
at the top.
当我这样做,我得到的红色波浪线的说,你是缺少程序集引用?当我尝试添加引用,从A-Z在对话框中单击.NET选项卡上,排序,我没有看到 System.Web.Optimization
。
When I do this, I get the red squiggly lines that say, "Are you missing an assembly reference?" When I try and add reference, and click on the .NET tab in the dialog, sort from A-Z, I do not see System.Web.Optimization
.
我怎么这个裁判添加到我的项目?谢谢你。
How do I add this ref to my project? Thanks.
推荐答案
该Microsoft.Web.Optimization包现在已经过时了。在ASP.NET(MVC)4及更高版本,你应该安装微软的ASP.NET Web优化框架:
The Microsoft.Web.Optimization package is now obsolete. With ASP.NET (MVC) 4 and higher you should install the Microsoft ASP.NET Web Optimization Framework:
-
从安装包:
Install-Package Microsoft.AspNet.Web.Optimization
创建和配置App_Start \\ BundleConfig.cs束(S):
Create and configure bundle(s) in App_Start\BundleConfig.cs:
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles) {
bundles.Add(new ScriptBundle("~/Scripts/jquery").Include(
"~/Scripts/Lib/jquery/jquery-{version}.js",
"~/Scripts/Lib/jquery/jquery.*",
"~/Scripts/Lib/jquery/jquery-ui-{version}.js")
);
bundles.Add(new ScriptBundle("~/Scripts/knockout").Include(
"~/Scripts/Lib/knockout/knockout-{version}.js",
"~/Scripts/Lib/knockout/knockout-deferred-updates.js")
);
}
}
在您的global.asax.cs调用来自的Application_Start()的RegisterBundles()函数:
Call the RegisterBundles() function from Application_Start() in your global.asax.cs:
using System.Web.Optimization;
protected void Application_Start() {
...
BundleConfig.RegisterBundles(BundleTable.Bundles);
...
}
在您view.cshtml包括优化空间和渲染包(S):
In your view.cshtml include the Optimization namespace and render the bundle(s):
@using System.Web.Optimization
@Scripts.Render("~/Scripts/jquery")
@Scripts.Render("~/Scripts/knockout")
请参阅了解更多信息。
更新结果
1.1.x版本的可用,阅读发行说明:<一href=\"http://aspnetoptimization.$c$cplex.com/releases/view/101096\">http://aspnetoptimization.$c$cplex.com/releases/view/101096
这篇关于如何引用添加到System.Web.Optimization对MVC-3转换到4应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!