我将使用Visual Studio 2010开发的旧版网站项目升级为Visual Studio 2013中的Web应用程序项目。现在,我想向该应用程序添加一些MVC组件,包括捆绑和缩小。但是App_Start文件夹丢失。我是否需要安装任何可以创建App_Start文件夹并添加捆绑和缩小功能的NuGet软件包?
I upgraded a legacy website project developed using Visual Studio 2010 to a Web Application project in Visual Studio 2013. Now I want to add some MVC components to this application including Bundling and Minification. But the App_Start folder is missing. Is there any NuGet package I need to install that would create the App_Start folder and add the 'Bundling and Minification' feature?
例如,该项目也缺少内容文件夹,但是当我通过NuGet软件包管理器安装jQuery UI 1.10.4软件包时,它创建了Content文件夹并向其中添加jQuery UI css文件。
For instance, this project was also missing the 'Content' folder, but when I installed the jQuery UI 1.10.4 package via NuGet package Manager, it created the Content folder and add jQuery UI css files to it.
推荐答案步骤1:(通过GUI)安装捆绑和压缩。 工具>图书包管理器>管理解决方案的NuGet程序包。在线搜索捆绑,第一个结果应该是 Microsoft ASP.NET Web优化框架。安装。
Step 1: Install Bundling and Minification (via the GUI). Tools > Library Package Manager > Manage NuGet Packages For Solution. Search Online for "bundling" and the first result should be Microsoft ASP.NET Web Optimization Framework. Install that.
步骤2:右键单击您的Web项目并添加新文件夹,并将其命名为 App_Start 。
Step 2: Right-click your Web Project and Add New Folder and call it App_Start.
步骤3:在 App_Start 中添加新类称为 BundleConfig.cs 。看起来可能像这样:
Step 3: Add a new class in App_Start called BundleConfig.cs. It could look like this:
using System.Web.Optimization; public class BundleConfig { public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-{version}.js")); } }步骤4:在global.asax中的ApplicationStart上:
Step 4: Load on ApplicationStart in global.asax:
void Application_Start(object sender, EventArgs e) { BundleConfig.RegisterBundles(BundleTable.Bundles); }步骤5:添加到MasterPage的页脚中。我通常会这样:
Step 5: Add to footer of MasterPage. I usually do like this:
<%: System.Web.Optimization.Scripts.Render("~/bundles/jquery") %> <asp:ContentPlaceHolder ID="MyScripts" runat="server"></asp:ContentPlaceHolder> </body> </html>这样,jQuery就会在< / body> 标记,您可以将所有内联脚本放入 ContentPlaceHolder 中,该脚本在引用主脚本后呈现。
That way, jQuery loads near the </body> tag and you can put all inline scripts in a ContentPlaceHolder that renders after your main script references.
更多推荐
我们如何将捆绑和缩小添加到从Visual Studio 2010项目升级的项目中
发布评论