如何在不更改构建脚本的情况下将gulp设置为在Visual Studio 2017和msbuild中相同地运行? [英] How can I set up gulp to run identically in Visual Studio 2017 and msbuild without having to change my build scripts?

查看:121
本文介绍了如何在不更改构建脚本的情况下将gulp设置为在Visual Studio 2017和msbuild中相同地运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力在Visual Studio 2017中设置gulp.我不确定哪里出错了,但是有些事情让我感到困惑,我真的找不到任何在线资源有什么用.

I'm struggling to get set up with gulp in Visual Studio 2017. I'm not sure where I'm going wrong but there are a few things I'm confused about and I can't really find any online resources that are of any use.

我正在使用的构建系统是CruiseControl.NET,我希望gulp可以使用它.

The build system I'm using is CruiseControl.NET and I would like gulp to work with it.

这是我到目前为止所做的:

This is what I've done so far:

  • 安装了Visual Studio 2017,并选择了.NET Core cross-platform developmentNode.js development(在其他选项中).

  • Installed Visual Studio 2017 with .NET Core cross-platform development and Node.js development selected (amongst other options).

创建了一个新项目

在项目中添加了gulpfile.js文件

右键单击文件,然后选择Task Runner Explorer

Right-click on the file and choose Task Runner Explorer

在Task Runner资源管理器中,出现错误Failed to load. See output window (Ctl+Alt+O) for more information..

In the Task Runner Explorer I get the error Failed to load. See output window (Ctl+Alt+O) for more information..

然后,如果我执行以下操作:

Then if I do the following:

  • 打开Node.js交互式窗口

  • Open the Node.js Interactive Window

运行命令.npm install --global gulp-cli

关闭Visual Studio并再次将其打开备份

Close Visual Studio and open it back up again

然后在Task Runner资源管理器中,收到消息(No tasks found).

In the Task Runner Explorer, I then get the message (No tasks found).

首先,这是在Visual Studio 2017中设置Gulp的正确方法吗?

First off, is this the correct way to set up Gulp in Visual Studio 2017?

我问这个问题的原因是因为我不确定为什么我需要在命令前加上句点字符(即.npm而不是npm).

The reason I'm asking this is because I'm not sure why I need to prefix commands with a period character (ie .npm as opposed to npm).

我也不确定gulp的安装位置,因为在路径C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Web\External\node_modules中找不到它.

I'm also not sure where gulp was installed because I can't find it in the path C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Web\External\node_modules.

因此,我无法真正设置CruiseControl.NET.

Because of this I can't really set up CruiseControl.NET.

推荐答案

Microsoft现在已添加有关如何使gulp运行的文档: https://docs.microsoft.com/zh-我们/aspnet/core/client-side/using-gulp

Microsoft have now added documentation on how to get gulp running: https://docs.microsoft.com/en-us/aspnet/core/client-side/using-gulp

确保将Visual Studio 2017更新到最新版本,因为它现在随Node.js,NPM和Gulp一起提供(为此安装Visual Studio时无需选择"Node.js支持")工作).

在您的项目文件夹中创建一个npm配置文件(package.json)并将其编辑以引用gulp:

Create an npm Configuration File (package.json) in your project folder and edit it to reference gulp:

{
  "version": "1.0.0",
  "name": "example",
  "private": true,
  "devDependencies": {
    "gulp": "3.9.1"
  },
  "scripts": {
    "gulp": "gulp"
  }
}

在项目文件夹中,创建一个Gulp配置文件(gulpfile.js)来定义自动化过程.

In the project folder, create a Gulp Configuration File (gulpfile.js) to define the automated process.

为需要gulp支持的每个项目,在构建后事件命令行中添加以下内容:

Add the following to the post-build event command line for each project requiring gulp support:

cd $(ProjectDir)
call dotnet restore
npm run gulp

要在Visual Studio 2017中运行任务,请打开任务运行程序资源管理器"(视图">其他Windows">任务运行程序资源管理器").

To run the tasks in Visual Studio 2017, open the Task Runner Explorer (View > Other Windows > Task Runner Explorer).

然后在构建服务器上只需安装Node.js并确保将节点的路径添加到环境路径变量中,然后在构建服务器构建项目时,gulp也将运行!

Then on the build server just install Node.js and ensure the path to node is added to the environmental path variable then when the build server builds the project gulp will run too!

这篇关于如何在不更改构建脚本的情况下将gulp设置为在Visual Studio 2017和msbuild中相同地运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆