Advanced Basics: Using Task Runner in Visual Studio 2019

Failed to run "C:workspaceCompanyFinland owdevelopSourceEdenredFi.WOTWebGulpfile.js"...
cmd.exe /c gulp --tasks-simple
'gulp' is not recognized as an internal or external command,
operable program or batch file.

Advanced Basics: Using Task Runner in Visual Studio 2019

If the world is running on JavaScript, why not automate your client-side tasks through Visual Studio's Task Runner?

With JavaScript as currently the primary language for developers, it made sense when Microsoft released Visual Studio 2019 to include client-side tools to simplify the JavaScript development process.

One of those tools was a Task Runner. 

When the Task Runner was introduced, developers of the C# community never even knew what it was or how it worked (including me).

Now, since I've dug into it, it proves it's another great tool in the DevOps toolbelt.

What is a Task Runner

A Task Runner is a tool to automate repetitive client-side tasks.

The tool runs off of a configuration file (either Gulp or Grunt) to execute on any number of static assets in a directory.

For this post, we'll focus on using Gulp with a gulpfile.js.

Setting up the Task Runner

In Visual Studio 2019, confirm you are running the latest Node version.

  1. Download the latest version of Node and install it normally.
  2. In Visual Studio, go to Tools, Options.
  3. Expand the Projects and Solutions, Web Package Management, then External Web Tools.
  4. Confirm $(PATH) is at the top of your "location of external tools"

If you installed NodeJs properly, it will be in your system path. The $(PATH) will point to that when a build process occurs.

Next, since a Task Runner uses Node for it's engine, we need a populated package.json file to hold the installed packages used in our Task Runner.

For starters, let's install our Gulp package.

  1. Open the Package Manager Console (View / Windows / Package Manager Console)
  2. Change into the directory containing the root of your solution.
  3. Type: npm install -g gulp

Examine the package.json file in the directory. It should contain a gulp entry:

"gulp""^4.0.2"

Once we have our package installed, we can use it in our test.

Task runner explorer可以在View-->Other windows中找到。

原文地址:https://www.cnblogs.com/chucklu/p/15132582.html