npm does not work with msbuild
<p>I am new to gulp and I am facing problem in integrating it with msbuild. I am trying to run tasks using gulp(e.g: minifying files) and even though it works perfectly when I build my project,it fails to run on msbuild. 
Here is the code for <strong>gulpfile.js</strong>:</p>

<pre><code>var gulp=require("gulp"),
gutil=require("gulp-util"),
uglify=require("gulp-uglify"),
debug=require("gulp-debug"),
concat=require("gulp-concat");
var uglifycss = require('gulp-uglifycss');
gulp.task("js",function(){
    gulp.src(["./**/*.js","!./**/*.min.*","!./**/gulpfile.js"])
    .pipe(uglify())
    .pipe(debug())
    .pipe(gulp.dest(function(file){return file.base}));

gulp.task('css', function () {
  gulp.src(["./**/*.css","!./**/*.min.*"])
    .pipe(uglifycss())
    .pipe(gulp.dest(function(file){return file.base}));
});
gulp.task("build",["js","css"]);
gulp.task('default', function(){
gulp.run('build'); 
});
</code></pre>

<p>this is called by a powershell script file compileClient.ps1:</p>

<pre><code>npm install -g gulp
npm install --save-dev gulp gulp-util
npm install --save-dev gulp-uglify gulp-concat
npm install --save gulp-uglifycss
npm install --save-dev gulp-debug
gulp
npm install -g rimraf
cmd /c $env:APPDATA\npm\rimraf ./node_modules
</code></pre>

<p>when I run this command on cmd, </p>

<pre><code>"%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe" -file "$(ProjectDir)compileClient.ps1"
</code></pre>

<p>It works fine and minifies the target files. I then tried putting this command in the post build event of my project and when I run it locally on visual studio it works fine too.</p>

<p>however when this project is built by msbuild, the same post-build event does not work,it gives the following message shown in the image below: 
<a href="http://i.stack.imgur.com/JkHDm.png" rel="nofollow">npm : the term 'npm' is not recognized as the name of a cmdlet..</a></p>

<p>I checked the PATH variable set by node and it is correct. Also when I do <strong>node -v</strong> on my cmd I could see the version of node installed, but when I do it on the msbuild command line it fails to identify node.</p>

<p>I used this blog as a reference
<a href="https://www.niclassahlin.com/2015/04/10/running-gulp-during-tfs-build/" rel="nofollow">https://www.niclassahlin.com/2015/04/10/running-gulp-during-tfs-build/</a></p>

<p>I would appreciate any help/advice on this matter, thanks.</p>