asp.net - 在 Visual Studio 构建中恢复 Bower 组件

标签 asp.net visual-studio-2015 bower asp.net-core-mvc kpm

我刚刚在 VS 2015 中创建了我的第一个 ASP.NET 5 MVC 6 项目。开箱即用的 Web 应用程序项目。

我发现 Bower 组件存储在 wwwroot/lib 文件夹中。我做了一个实验,然后删除了。之后我重建了项目,并且 Bower 组件恢复。

在控制台中手动调用bower install恢复了文件。

如何让 Visual Studio 在构建时自动恢复 Bower 文件?

最佳答案

我找到了一种方法来做到这一点,尽管我不太喜欢它。我很乐意接受更好的答案。

在项目的 gulpfile.js 中,第一行是注释”

/// <binding Clean='clean'/>

它 Hook Visual Studio Clean 事件并将 clean Gulp 任务绑定(bind)到它。 您可以 Hook 其他事件,例如构建后。我将它与使用 gulp-bower 的任务绑定(bind)在一起恢复组件。

gulpfile.js

/// <binding Clean='clean' AfterBuild='after_build'/>

var gulp = require("gulp"),
    bower = require('gulp-bower');

...

gulp.task("after_build", function() {
    return bower()
        .pipe(gulp.dest(paths.webroot + 'lib/'));
});

您可以在Task Runner Explorer中看到绑定(bind): enter image description here

这个解决方案看起来有点笨拙。我宁愿让 kpm 实用程序来完成这项工作。

编辑

实际上不需要在构建时恢复包。当您在 VS 中打开项目时,它们会被恢复。但是我不知道当您从代码存储库更新源代码时会发生什么。

关于asp.net - 在 Visual Studio 构建中恢复 Bower 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32291658/

相关文章:

ruby-on-rails - 如何在 rails-assets.org 中包含一个带有 .在名字里?

angularjs - gulp-inject 未加载所有 Bower 组件

c# - "dotnet has stopped working"添加数据库迁移时出现StackOverflowException

鲍尔 throw 错误

c# - 如何从 Excel 中解析 "cut n paste"

c# - Store 没有实现 IUserPasswordStore<TUser> ASP.NET Identity

c# - asp.net .asmx web 服务 ishow XXE 漏洞 - 外部 DNS

c# - 文本框中的背景文本

asp.net-mvc - 由于vs2015中invokepowershell失败,无法发布mvc6应用程序

c++ - 为什么 "this"在具有多个基类的类的父类中发生变化?