Vishnu Vishnu - 1 month ago 7
ASP.NET (C#) Question

How to run Grunt command from Visual Studio?

I have written Grunt task for minifying and combining multiple scripts and styles in each single file for Visual Studio ASP.NET project.

This grunt task can be run on project solution directory as follows and works fine.


  1. Open command Prompt (cmd.exe)

  2. Go to Project directory
    cd /Visual/Studio/Project/Directory/

  3. Run grunt command line
    grunt



It works fine. I need that this task should be run automatically in screen behind (or output window) when I save any
.js
or
.css
file in that project directory

Answer

Till now I have succeeded in running the above process using a shortcut as follows:

I. Add External Tool

  1. Go to External Tools under Tools menu in Visual Studio
  2. Click on Add, write following details:

    Title: Grunt  
    Command : C:\Windows\System32\cmd.exe
    Arguments: /k grunt
    Initial Directory: $(ProjectDir)
    
    Optionally, check **Use Output Directory** option.
    

    enter image description here

  3. Move the item to top in External Tools Click OK

II. Add shortcut to External Command

Reference

  1. Go to Tools menu, click Options.
  2. Select Keyboard on the Environment page.
  3. In the Show commands containing list, type Tools.
  4. In the Command names list, locate the appropriate External Command n entry.
  5. Put the cursor in the Press shortcut keys box, and then press the keys you want to assign to the external tool.
  6. Click Assign

So, now the grunt task can be run from a shortcut. But still I could not make it run automatically on saving a file(.js/.css).

Comments