Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

Run Grunt task in Visual Studio Release Build with a bat file

, 21 Aug 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Originally posted on: http://geekswithblogs.net/Aligned/archive/2014/08/19/run-grunt-task-in-visual-studio-release-build-with-a.aspx1. Add a BeforeBuild in your csproj file. Edit the xml with a text editor.  2. Create the script-optimize.batREM "%~dp0" maps to the directory where this file ex

Originally posted on: http://geekswithblogs.net/Aligned/archive/2014/08/19/run-grunt-task-in-visual-studio-release-build-with-a.aspx

1. Add a BeforeBuild in your csproj file. Edit the xml with a text editor.
  <Target Name=<span class="str" style="color: #006080">"BeforeBuild"</span>>
    <Exec Condition=<span class="str" style="color: #006080">"'$(Configuration)' == 'Release'"</span> Command=<span class="str" style="color: #006080">"script-optimize.bat"</span> />
  </Target>
 
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 <a href="http://gruntjs.com" target="_blank">grunt</a> command will compile typescript, run the requireJs optimizer, complie 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">
    <ItemGroup>
      <_CustomFiles Include="Scripts-Release\**\*" />
  </ItemGroup>
  </Target>

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, ect. I highly recommend it.

License

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

Share

About the Author

Aligned
Web Developer
United States United States
No Biography provided

Comments and Discussions

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