0

I'm facing issue running gulp successfully for installing Habitat with VS2017 Community edition.

I've checked the Node version, msbuild version and all is fine. But when I run gulp it automatically detects msbuild path as:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe

where as the actual path is:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64\MSBuild.exe

Any help to fix the msbuild path detection by gulp would be really appreaciated.

Below is the error I'm facing:

C:\projects\Habitat>gulp
[11:57:14] O---o   _____ _ _                            _   _      _ _
[11:57:14]  O-o   /  ___(_) |                          | | | |    | (_)
[11:57:14]   O    \ `--. _| |_ ___  ___ ___  _ __ ___  | |_| | ___| |___  __
[11:57:14]  o-O    `--. \ | __/ _ \/ __/ _ \| '__/ _ \ |  _  |/ _ \ | \ \/ /
[11:57:14] o---O  /\__/ / | ||  __/ (_| (_) | | |  __/ | | | |  __/ | |>  <
[11:57:14] O---o  \____/|_|\__\___|\___\___/|_|  \___| \_| |_/\___|_|_/_/\_\
[11:57:14]  O-o
[11:57:14]   O    -------------------- helix.sitecore.net ------------------
[11:57:14]  o-O
[11:57:14] o---O  The Habitat source code, tools and processes are examples of 
Sitecore Helix.
[11:57:14] O---o  Habitat is not supported by Sitecore and should be used at your own risk.
[11:57:14]  O-o
[11:57:14]   O    ----------------------------------------------------------
[11:57:14]  o-O
[11:57:14] o---O
[11:57:14] Using gulpfile C:\projects\Habitat\gulpfile.js
[11:57:14] Starting 'default'...
[11:57:14] Starting '01-Copy-Sitecore-License'...
Copying Sitecore License file
[11:57:14] Finished '01-Copy-Sitecore-License' after 43 ms
[11:57:14] Starting '02-Nuget-Restore'...
[11:57:15] MSBuild auto-detection: using msbuild version '4.0' from 'C:\Windows\Microsoft.NET\Framework\v4.0.30319'.
All packages listed in packages.config are already installed.
[11:57:15] Finished '02-Nuget-Restore' after 1.01 s
[11:57:15] Starting '03-Publish-All-Projects'...
[11:57:15] Starting 'Build-Solution'...
[11:57:15] { Error: spawn C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe ENOENT
    at exports._errnoException (util.js:1020:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:197:32)
    at onErrorNT (internal/child_process.js:376:16)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'spawn C:\\Program Files (x86)\\Microsoft Visual 
Studio\\2017\\Enterprise\\MSBuild\\15.0\\Bin\\amd64\\MSBuild.exe',
  path: 'C:\\Program Files (x86)\\Microsoft Visual 
Studio\\2017\\Enterprise\\MSBuild\\15.0\\Bin\\amd64\\MSBuild.exe',
  spawnargs:
   [ 'C:\\projects\\Habitat\\Habitat.sln',
     '/target:Clean;Build',
     '/verbosity:minimal',
     '/toolsversion:15.0',
     '/nologo',
     '/maxcpucount',
     '/nodeReuse:False',
     '/property:Configuration=Debug',
     '/property:Platform=Any CPU' ] }
[11:57:15] MSBuild failed!
[11:57:15] 'Build-Solution' errored after 26 ms
[11:57:15] Error: spawn C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe ENOENT
    at exports._errnoException (util.js:1020:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:197:32)
    at onErrorNT (internal/child_process.js:376:16)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
[11:57:15] 'default' errored after 1.11 s
[11:57:15] Error in plugin 'run-sequence(Build-Solution)'
Message:
    spawn C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe ENOENT
Details:
    code: ENOENT
    errno: ENOENT
    syscall: spawn C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe
    path: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe
    spawnargs: C:\projects\Habitat\Habitat.sln,/target:Clean;Build,/verbosity:minimal,/toolsversion:15.0,/nologo,/maxcpucount,/nodeReuse:False,/property:Configuration=Debug,/property:Platform=Any CPU
Stack:
Error: spawn C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe ENOENT
    at exports._errnoException (util.js:1020:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:197:32)
    at onErrorNT (internal/child_process.js:376:16)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
[11:57:15] '03-Publish-All-Projects' errored after 48 ms
[11:57:15] Error in plugin 'run-sequence(default)'
Message:
    spawn C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe ENOENT
Details:
    code: ENOENT
    errno: ENOENT
    syscall: spawn C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe
    path: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe
    spawnargs: C:\projects\Habitat\Habitat.sln,/target:Clean;Build,/verbosity:minimal,/toolsversion:15.0,/nologo,/maxcpucount,/nodeReuse:False,/property:Configuration=Debug,/property:Platform=Any CPU
Stack:
Error: spawn C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe ENOENT
    at exports._errnoException (util.js:1020:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:197:32)
    at onErrorNT (internal/child_process.js:376:16)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
[11:57:15] '03-Publish-All-Projects' errored after 55 ms
[11:57:15] Error in plugin 'run-sequence(Build-Solution)'
Message:
    spawn C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe ENOENT
Details:
    code: ENOENT
    errno: ENOENT
    syscall: spawn C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe
    path: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe
    spawnargs: C:\projects\Habitat\Habitat.sln,/target:Clean;Build,/verbosity:minimal,/toolsversion:15.0,/nologo,/maxcpucount,/nodeReuse:False,/property:Configuration=Debug,/property:Platform=Any CPU
Stack:
Error: spawn C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe ENOENT
    at exports._errnoException (util.js:1020:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:197:32)
    at onErrorNT (internal/child_process.js:376:16)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)

Below is my Packacge.json:

{
  "name": "habitat",
  "version": "1.0.0",
  "description": "Sitecore Habitat Node Dependencies",
  "main": "gulpfile.js",
  "dependencies": {
    "async": "^1.5.2",
    "glob": "^7.0.3",
    "gulp": "^3.9.0",
    "gulp-autoprefixer": "^3.1.0",
    "gulp-debug": "^2.1.2",
    "gulp-exec": "^2.1.2",
    "gulp-foreach": "^0.1.0",
    "gulp-load-plugins": "^1.0.0",
    "gulp-msbuild": "^0.4.4",
    "gulp-newer": "^1.0.0",
    "gulp-rename": "^1.2.2",
    "gulp-rimraf": "^0.2.0",
    "gulp-sass": "^2.0.4",
    "gulp-util": "^3.0.7",
    "gulp-watch": "^4.3.5",
    "merge-stream": "^1.0.0",
    "node-sass": "^4.5.3",
    "rimraf": "^2.4.3",
    "run-sequence": "^1.1.4",
    "vinyl": "^1.1.0",
    "xml2js": "^0.4.16",
    "xmlpoke": "^0.1.12",
    "yargs": "^6.4.0"
  },
  "devDependencies": {
    "gulp-msbuild": "^0.4.8",
    "gulp-nuget-restore": "^0.4.0"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/Sitecore/Habitat.git"
  },
  "author": "Sitecore Corporation A/S",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/Sitecore/Habitat/issues"
  },
  "homepage": "https://github.com/Sitecore/Habitat#readme"
}

gulp-config.js:

module.exports = function () {
  var instanceRoot = "C:\\websites\\Habitat.dev.local";
  var config = {
    websiteRoot: instanceRoot + "\\Website",
    sitecoreLibraries: instanceRoot + "\\Website\\bin",
    licensePath: instanceRoot + "\\Data\\license.xml",
    solutionName: "Habitat",
    buildConfiguration: "Debug",
    buildToolsVersion: 15.0,
    buildMaxCpuCount: 0,
    buildVerbosity: "minimal",
    buildPlatform: "Any CPU",
    publishPlatform: "AnyCpu",
    runCleanBuilds: false
  };
  return config;
}

gulp task:

gulp.task("03-Publish-All-Projects", function (callback) {
  return runSequence(
    "Build-Solution",
    "Publish-Foundation-Projects",
    "Publish-Feature-Projects",
    "Publish-Project-Projects", callback);
});
gulp.task("Build-Solution", function () {
  var targets = ["Build"];
  if (config.runCleanBuilds) {
    targets = ["Clean", "Build"];
  }

  var solution = "./" + config.solutionName + ".sln";
  return gulp.src(solution)
      .pipe(msbuild({
          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.buildPlatform
          }
        }));
});
1

The current master branch of Habitat is using v0.4.4 of the gulp-msbuild package. That version was still using an iterative process to figure out the location of msbuild. Priority is given to the following versions, in order:

  1. BuildTools
  2. Enterprise
  3. Professional
  4. Community

This is a pretty limited process, because it doesn't allow for non-standard installations. It looks for each of the above folder names within C:\Program Files (x86)\Microsoft Visual Studio\2017. When it finds a folder that exists, it's considered the official version for building. So presumably you do have that folder on your drive: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise. Removing it, if not needed, would resolve your issue.

What I would recommend though is updating the gulp-msbuild package (from your solution root: npm update gulp-msbuild --save). Since that version, this package has been updated to use vswhere in order to locate msbuild. You can see the change in this commit on GitHub.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.