0

I wonder if I could get the ASP.NET project configuration and platform in gulpfile.js or gruntfile.js? I mean e.g. Debug|AnyCPU values.

Nickon
  • 8,180
  • 10
  • 52
  • 105

1 Answers1

1

Yes you can, but for obvious reasons you only can if you call gulp from a tool that knows those details, e.g. msbuild.

Suppose you've just created a fresh, Empty ASP.NET Web Application for .NET 4.5.2 using Visual Studio 2015, you can add something like this to the Build or AfterBuild Target:

<exec command='gulp --env="$(Configuration)|$(Platform)"' />

You then need to parse arguments in gulp, e.g. using yargs:

require('gulp').task("default", function() {
  console.log(require('yargs').argv.env);
});

This will write something like this if you build in Visual Studio:

  1>------ Rebuild All started: Project: GulpFromMsbuild, Configuration: Release Any CPU ------
  1>  GulpFromMsbuild -> D:\GulpFromMsbuild\bin\GulpFromMsbuild.dll
  1>  [20:07:41] Using gulpfile D:\GulpFromMsbuild\gulpfile.js
  1>  [20:07:41] Starting 'default'...
  1>  Release|AnyCPU
  1>  [20:07:41] Finished 'default' after 36 ms
  ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

So basically two ingredients:

  1. Pass the mode from your calling tool (msbuild, teamcity, powershell, whatever);
  2. Parse the argument in gulp (yargs, etc);

I'd assume there's a similar argument-parsing tool for Grunt...

Community
  • 1
  • 1
Jeroen
  • 53,290
  • 30
  • 172
  • 279