我们如何将捆绑和缩小添加到从Visual Studio 2010项目升级的项目中

编程入门 行业动态 更新时间:2024-10-16 20:29:53
本文介绍了我们如何将捆绑和缩小添加到从Visual Studio 2010项目升级的项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我将使用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项目升级的项目中

本文发布于:2023-11-11 05:44:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577542.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   如何将   Studio   Visual

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!