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相关问答推荐

在 ASP.NET 中访问没有值的查询字符串参数

解析器错误消息:文件/TestSite/Default.aspx.cs不存在

System.Web.Helpers.Crypto - 盐在哪里?

在控制器 asp.net mvc 5 的视图上显示错误消息

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

如何将 ASP.NET MVC5 身份验证添加到现有数据库

在 ASP.NET 中将虚拟路径转换为实际 Web 路径

如何使用自动生成的列隐藏 ASP.NET GridView 中的列?

Ef core:执行 MaxAsync 时序列不包含任何元素

对于每个请求,RestClient 应该是单例还是新的

.Net Standard 2.0 类库是否有通用配置文件?

Eval()、XPath() 和 Bind() 等数据绑定方法只能在数据绑定控件的上下文中使用

IIS 10 上的 ASP.NET Core 404 错误

将 Http 请求读入字节数组

如何在 ASP.NET MVC 中设置时区?

会员生成密码 仅限字母数字密码?

当用户在文本框中按 Enter 键时执行按钮单击事件

如何在服务器控件属性中使用 ASP.NET <%= 标签?

如何创建代表 colored颜色 的随机十六进制字符串?

Appdomain 回收究竟是什么