如何将 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?

查看:21
本文介绍了如何将 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 跨平台开发Node.js 开发(以及其他选项).

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

创建了一个新项目

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

Added a gulpfile.js file to the project

右击文件并选择Task Runner Explorer

在 Task Runner Explorer 中,我收到错误 Failed to load.有关详细信息,请参阅输出窗口 (Ctl+Alt+O)..

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

如果我执行以下操作:

  • 打开 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 Explorer 中,我收到消息 (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 Studio2017ProfessionalWebExternal ode_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 Studio2017ProfessionalWebExternal ode_modules.

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

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

推荐答案

微软现在添加了关于如何让 gulp 运行的文档:https://docs.microsoft.com/en-我们/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 中运行任务,请打开 Task Runner Explorer(查看 > 其他 Windows > Task Runner Explorer).

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天全站免登陆