Visual Studio 2019 and Gulp script for Sitecore Habitat

If you are using Visual Studio 2019 and have the Habitat project and trying to run the Gulp script, You might find that you are getting errors.

It might look like this
{ Error: spawn C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\15.0\Bin\amd64\MSBuild.exe ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:232:19)
at onErrorNT (internal/child_process.js:407:16)
at process._tickCallback (internal/process/next_tick.js:63:19)

This is an issue with gulp-msbuild and it looking at a wrong path. Also gulp-msbuild is no longer being maintained. You can easily fix this by using msbuild in following way.

I am using gulp 3.9.1. But you can easily do it for gulp 4. But note that gulp 4 has couple new functionalities that you have to consider.
Let’s get started

  1. Install gulp if you haven’t already
    npm install gulp@3.9.1
  2.  Install gulp locally.
    a. Go to your folder
    b. run this command
    npm install gulp@3.9.1 –save-dev
  3. ¬†let’s install msbuild locally too
    npm install msbuild –save-dev


//————————————- Here is habitat code —————
…(excluding for brevity)
var msbuild = require(“gulp-msbuild”);

var publishStream = function(stream, dest) {
var targets = [“Build”];

return stream
.pipe(debug({ title: “Building project:” }))
targets: targets,
configuration: config.buildConfiguration,
logCommand: false,
verbosity: config.buildVerbosity,
stdout: true,
errorOnFail: true,
maxcpucount: config.buildMaxCpuCount,
nodeReuse: false,
toolsVersion: config.buildToolsVersion,
properties: {
Platform: config.publishPlatform,
DeployOnBuild: “true”,
DeployDefaultTarget: “WebPublish”,
WebPublishMethod: “FileSystem”,
BuildProjectReferences: “false”,
DeleteExistingFiles: “false”,
publishUrl: dest

//——- End of Habitat code ——————

//——— Here are the new replacement ———–
…(excluding for brevity)
var _msbuild = require(“msbuild”);
msbuild = new _msbuild();

msbuild.sourcePath= ‘c:/[yourlocation]/your_app.sln’;
msbuild.configuration = ‘Debug’;
msbuild.buildPlatform=’Any CPU’;
//to use any custom param you can use
[add all your other values here];
//———– End of Replacement —————–

This should solve the issues with the Gulp script on Visual Studio 2019.

I have to give my shout out to the following link

Thank you for reading.