BundleConfig
無非是捆綁配置移動到單獨的文件。它曾經是應用程序的啓動代碼的一部分(過濾器,捆綁,使用的路線是在一個類中配置)
要添加此文件,首先您需要將Microsoft.AspNet.Web.Optimization
NuGet包添加到您的Web項目:
Install-Package Microsoft.AspNet.Web.Optimization
然後在App_Start文件夾下創建一個名爲BundleConfig.cs
的新cs文件。以下是我在我礦(ASP.NET MVC 5,但它應該與MVC 4工作):
using System.Web;
using System.Web.Optimization;
namespace CodeRepository.Web
{
public class BundleConfig
{
// For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
}
}
}
然後修改您的Global.asax和呼叫添加到RegisterBundles()
在Application_Start()
:
using System.Web.Optimization;
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
密切相關的問題:使用 「MVC 5」 沒有看到文件How to add reference to System.Web.Optimization for MVC-3-converted-to-4 app
來源
2014-02-10 02:54:16
vmg
您找不到它,因爲它只包含在ASP.NET 4.5項目模板中。我假設你正在使用早期版本的ASP.NET。 –
不,ASP.Net 4.5。 – Maverick
[如何爲MVC-3轉換爲4應用程序添加對System.Web.Optimization的引用]的可能重複(http://stackoverflow.com/questions/9475893/how-to-add-reference-to- system-web-optimization-for-mvc-3-converted-to-4-app) – Liam