hoffi/gulp-msbuild

VS 2017 Developer Command Prompt finds msbuild 14.0

Closed this issue · 10 comments

Hello,

I'm running gulp-msbuild 0.4.7 which I think was released to fix #52.

Unfortunately I'm still having the same/similar issue:
image

Happy to help diagnose if you can point me to what I should be checking for.

Thanks!

hoffi commented

gulp-msbuild checks wether one these paths exist:

  • C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools
  • C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise
  • C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional
  • C:/Program Files (x86)/Microsoft Visual Studio/2017/Community

If none of those paths exist, gulp-msbuild assumes it is not installed.
Can you check where your MSBuild 15 executable is located?

Here's what's on my machine for all msbuild.exe under Program Files (x86):

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

Whether I run the gulp script from a VS2015 dev command prompt, or a VS2017 command prompt, it always finds version 14.

I've tried to reproduce this in a clean project on that same machine but cannot, so closing this.

I have the same issue. I have 2013, 2015 and 2017 installed. The msbuild does not detect 2017 and uses 2015. Just for fun I uninstalled 2015, now it falls back to 2013. 2017 is simply not detected and I have both paths: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools and C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional existing on my drive.

UPDATE:
I have been adding some debugging print statements, and it seems the gulp plugin is finding the correct VS2017 path, however some how (I'm not to familiar with gulp) there is some sort of MS-Build auto detection happening even before gulp-msbuild autodetects the paths itself. See the code below from index.js

 module.exports = function(options) {
    var mergedOptions = _.cloneDeep(mergeOptionsWithDefaults(options));
    validateOptions(mergedOptions);

    gutil.log(gutil.colors.cyan('Line: '), '1');

    var stream = through.obj(function(file, enc, callback) {
    var self = this;
    gutil.log(gutil.colors.cyan('Line: '), '2');
    if (!file || !file.path) {
      self.push(file);
      gutil.log(gutil.colors.cyan('Line: '), '3');
      return callback();
    }

    gutil.log(gutil.colors.cyan('Line: '), '4');
    return msbuildRunner.startMsBuildTask(mergedOptions, file, function (err)
    {
      gutil.log(gutil.colors.cyan('Line: '), '5');
      if (err) return callback(err);
      self.push(file);
      if (mergedOptions.emitEndEvent) self.emit("end");
      return callback();
    });
  });

  return stream;
};

Some how between 'Line 1' and 'Line 2' some other mystical process is happening and the following output is observed:

[15:36:57] Starting 'build-servicestack'...
Building Configuration: Debug
[15:36:57] Line:  1
[15:36:57] MSBuild auto-detection: using msbuild version '12.0' from 'C:\Program Files (x86)\MSBuild\12.0\bin'.
All packages listed in packages.config are already installed.

[15:36:57] Line:  2

When I output the path actually being used by msbuild-runner.js:

gutil.log(gutil.colors.cyan('Running executable: '), command.executable);
var cp = childProcess.spawn(command.executable, command.args, spawnOptions);

I get:

[15:50:04] Using msBuild path:  C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\amd64\MSBuild.exe

So there is something else being triggered somehow that causes this confusing MsBuild auto-detect message to be produced which is incorrectly implying what version of MSbuild the plugin is using.

hoffi commented

Hi @Bitfiddler, this is strange, do you run any other gulp tasks before?
gulp-msbuild does not use any tool for the msbuild autodetection and the message you got is nowhere in the code, so I would assume this comes from any other task of your gulpfile.

The msbuild process itself would only be started between line 4 and 5.

Hi @hoffi , I am still fairly new to building with gulp/npm/jspm with visual studio and msbuild so I can't say for certain what's going on (I'm using a scaffold project combined from Aurelia and ServiceStack) but I did a text search for anything referencing/using msbuild and the only results were from the gulp task that runs gulp-msbuild and from the plugin itself and the visual studio project file. Also, this auto-detection only happens when the gulp-msbuild task is in play. If I run any of my other gulp tasks that do not in turn launch gulp-msbuild, I do not get this message. I usually try not to label things as 'mystical', but in this case it is truly weird that this message comes up (and from the sounds of it, we are in the same boat on this).

Aha! perhaps I have found the culprit: gulp-nuget-restore
This does run before my msbuild task and apparently it also uses msbuild. I am in the process of figuring out if/how this can be fixed so as not to cause confusion in the future, but I think this line of thinking is a good bet.

Yep, it was gulp-nuget-restore that was the issue. It is using it's own copy of nuget version 3.4.4 which is pre-VS2017 so it does not detect it. I will post there. Thanks for your time and attention @hoffi, perhaps we leave this discussion here for others in case they run into this.

hoffi commented

No problem :)

@Bitfiddler did you get this resolved with gulp-nuget-restore?