Visual Studio 2015内置了对Grunt、Bower、Gulp和NPM for ASP等工具的支持.NET 5个项目.

然而,当我创建一个ASP.NET 4.5.2项目使用Visual Studio 2015它不使用这些工具.我想使用bower而不是nuget来管理客户端包.

我可以找到有关在Visual Studio 2013中使用这些工具的信息(例如,请参见this个问题).但我想Visual Studio 2015的过程是不同的,因为它内置了对这些工具的支持.

推荐答案

虽然Liviu Costea's answer是正确的,但我还是花了相当长的时间才弄明白它实际上是如何做到的.下面是我从一个新的ASP开始的分步指南.NET 4.5.2 MVC项目.本指南包括使用bower进行客户端软件包管理,但(尚未)涵盖Bundle /咕噜/咕噜声.

Step 1 (Create Project)

使用Visual Studio 2015创建新的ASP.NET 4.5.2项目(MVC模板).

Step 2 (删除 Bundling/Optimization from Project)

步骤2.1

卸载以下Nuget软件包:

  • 独自创立
  • Microsoft.jQuery.Unobstrusive.Validation
  • jQuery.验证
  • jQuery
  • 微软AspNet.网状物优化
  • WebGrease
  • 鹿角
  • 现代化者
  • 回应

步骤2.2

从项目中删除App_Start\BundleConfig.cs.

步骤2.3

删除

using System.Web.Optimization;

BundleConfig.RegisterBundles(BundleTable.Bundles);

Global.asax.cs

步骤2.4

删除

<add namespace="System.Web.Optimization"/>

Views\Web.config

步骤2.5

删除 Assembly Bindings for System.Web.OptimizationWebGrease from Web.config

Step 3 (Add bower to Project)

步骤3.1

将新的package.json文件添加到项目(NPM configuration file项模板)

步骤3.2

bower加到devDependencies:

{
  "version": "1.0.0",
  "name": "ASP.NET",
  "private": true,
  "devDependencies": {
    "bower": "1.4.1"
  }
}

保存package.json时会自动安装Bower软件包.

Step 4 (Configure bower)

步骤4.1

将新的bower.json文件添加到项目(Bower Configuration file项模板)

步骤4.2

Add 独自创立, jquery-validation-unobtrusive, modernizrrespond to dependencies:

{
  "name": "ASP.NET",
  "private": true,
  "dependencies": {
    "独自创立": "*",
    "jquery-validation-unobtrusive": "*",
    "modernizr": "*",
    "respond": "*"
  }
}

These packages 和 their dependencies are automatically installed when bower.json is saved.

Step 5 (Modify Views\Shared\_Layout.cshtml)

步骤5.1

代替

@Styles.Render("~/Content/css")

具有

<link rel="stylesheet" href="~/wwwroot/lib/独自创立/dist/css/独自创立.min.css" />
<link rel="stylesheet" href="~/Content/Site.css" />

步骤5.2

代替

@Scripts.Render("~/bundles/modernizr")

具有

<script src="~/wwwroot/lib/modernizr/modernizr.js" ></script>

步骤5.3

代替

@Scripts.Render("~/bundles/jquery")

具有

<script src="~/wwwroot/lib/jquery/dist/jquery.min.js"></script>

步骤5.4

代替

@Scripts.Render("~/bundles/独自创立")

具有

<script src="~/wwwroot/lib/独自创立/dist/js/独自创立.min.js"></script>
<script src="~/wwwroot/lib/respond/dest/respond.min.js"></script>

Step 6 (Modify other sources)

在所有其他视图中替换

@Scripts.Render("~/bundles/jqueryval")

具有

<script src="~/wwwroot/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>

Useful Links


Bundling & Minifying

In the comments below LavaHot recommends the Bundler & Minifier extension as a replacement for the default bundler which I remove in step 2. He also recommends this article on bundling 具有 Gulp.

Asp.net相关问答推荐

JWT 和 Google 在 Razor 页面中进行身份验证和授权

HttpRuntime.Cache[] 与 Application[]

如何使多行的 TextBox 控件无法调整大小?

威胁已经被清除了

解析 JSON 响应的最简单方法

异步编程与线程有什么不同?

在 RedirectToAction 调用中传播 QueryString 参数

如何使用 javascript 调用 ASP.NET c# 方法

为什么对 ASP.NET MVC 控制器的调用不执行 DelegatingHandler?

如何将图像 url 转换为 system.drawing.image

在 Visual Studio 2010 Professional 中找不到请求的 .Net Framework 数据提供程序

对 ASP.NET 2.0 网页进行单元测试的最佳方法是什么?

如何在 ASP.NET 中通过 LAN 访问您的网站

ASP.NET MVC 4 的 Windows 身份验证 - 它是如何工作的,如何测试它

头标记中的内联代码 - ASP.NET

调查 Web.Config 重复部分原因的步骤

回发后运行javascript函数

在 Asp.Net MVC 5 中获取登录用户的用户 ID

在 Visual Studio 2013 中更改项目端口号

如何将 DataTable 转换为类 Object?