Click here to Skip to main content
13,046,087 members (67,530 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 21 Aug 2014

Run Grunt Task in Visual Studio Release Build with a bat File

, 21 Aug 2014
Rate this:
Please Sign up or sign in to vote.
Run Grunt Task in Visual Studio Release Build with a bat File

Originally posted on

  1. Add a BeforeBuild in your csproj file. Edit the XML with a text editor.
    <Target Name="BeforeBuild">
      <Exec Condition="'$(Configuration)' == 'Release'" Command="script-optimize.bat" />
  2. Create the script-optimize.bat:
    REM "%~dp0" maps to the directory where this file exists
    cd %~dp0\..\YourProjectFolder
    call npm uninstall grunt
    call npm uninstall grunt
    call npm install --cache-min 604800 -g grunt-cli
    call npm install --cache-min 604800
    grunt typescript requirejs copy less:compile less:mincompile

    This grunt command will compile typescript, run the requireJs optimizer, compile and minimize less.

  3. Make it use the minified code when the Web.config compilation debug is set to false.
    <!-- These CustomCollectFiles actions are used so that 
            the Scripts-Release folder/files are included
            when publishing even though they are not project references -->
      <Target Name="CustomCollectFiles">
          <_CustomFiles Include="Scripts-Release\**\*" />

That should be all you need to get a Grunt task to minify and combine JS (plus other tasks) in Visual Studio Release build with debug = false.

This is a great video of Steve Sanderson talking about SPAs, npm, Knockout, Grunt, Gulp, etc. I highly recommend it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 22 Aug 2014
Article Copyright 2014 by Aligned
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid