Can I use Grunt with TFS?

前端 未结 5 1843
逝去的感伤
逝去的感伤 2020-12-24 03:58

My new project needs me to work with TFS + Git.

Confession: I know nothing about TFS.

I want to setup a build for my JavaScript project. I want to use Grunt.

相关标签:
5条回答
  • 2020-12-24 04:25

    On our current project, we're using Grunt and TFS. I've integrated Grunt with TFS by caling it from a bat file which you can hook up in the Pre- or Post-BuildEvents section of your project file.

    However, because TFS will execute your builds with specific environment variables, you need to use absolute paths.

    A list of the things we've done

    1. Install node.js on your build machine (as well as on your development machine(s) ofcourse)
    2. Add a package.jsonfile on the root of your JavaScript project.
    3. Use npm to install grunt-cli locally (!). Use the --save-dev flag to add this package to the development dependencies section in package.json
    4. For all other packages you need, use npm with the same flag as in step 3
    5. Write a bat file (see example below) in which you'll
      1. make use of absolute paths
      2. use npm to install all the packages listed in the packages.json file
      3. call grunt
    6. In your Pre- or PostBuildEvents, call this bat file

    bat file example

    rem use call to execute other bat files
    echo npm install 
    call "C:\Program Files\nodejs\npm" install
    
    rem because we have listed grunt-cli as a dev dependency,
    rem the executable will be located in the node_modules folder
    echo grunt
    call "./node_modules/.bin/grunt"
    
    0 讨论(0)
  • 2020-12-24 04:34

    After installing node etc... on your build server, you could also modify your build template and add a step to call grunt etc.... This would prevent you from having to modify your csproj file and allow you to use the environmental variables created by TFS instead.

    0 讨论(0)
  • 2020-12-24 04:35

    I use grunt with TFS when I have to use TFS. I've tried grunt-tfs-unlock, but ran into this issue. I solved the problem using grunt-shell, which works and leaves you more in charge of the configuration. This gist shows how I use TFS with grunt. It demonstrates the 'tf checkout' command, but you could easily create any tf command with this pattern.

    0 讨论(0)
  • 2020-12-24 04:36

    You can find a full example scenario on how to use grunt on the build server: http://www.codit.eu/blog/2015/03/18/continuous-integration-with-javascript-nunit-on-tfsbuild-(part-23)/

    0 讨论(0)
  • 2020-12-24 04:47

    I tried all the answers listed here and wasn't able to get a successful automated build and deploy with TFS until I used NCapsulate. It removes the need for NodeJs to be installed separately on build agents or dev machines. Just a NuGet package.

    Just make sure you set up your build targets properly and it works very well.

    0 讨论(0)
提交回复
热议问题