Upload custom build task after TFS 2017 Update 1

By Mirek on (tags: build, tfs, vNext, categories: tools, infrastructure)

Over a year ago I’ve posted a guide on how to upload a custom build task to Team Foundation Server 2015. The solution was based on a TFS REST api which allowed to manipulate build tasks easily. Things have changed since then unfortunately…

Now in TFS 2017 after Update 1 this option is not available any more. The REST API is still there and you can get the json definition of the build step by calling

however the POST method is unavailable. We cannot upload the task.

There is a different approach required to reach this goal. Let me explain it in steps.

  1. First you have to install the Cross-platform CLI for Team Foundation Server and Visual Studio Team Services
  2. Then you have to go to your TFS web portal and create your personal access token. This token will be used to connect to the TFS server from the machine you are going to upload the stuff from.
    If you prefer to use basic, username – password, authentication you have two options. Either you go to the TFS server machine and do everything up there locally or you have to enable Basic authentication mode on the TFS server web portal (instructions here). The latter is not recommended solution though.
    In this tutorial we will connect to the TFS server from a client machine and we are using the PAT (Personal Access Token) authentication.
  3. Open command prompt in admin mode.
  4. First we login to the TFS server so won’t need to repeat the credentials on every command
    Type: tfx login
    Url: http://{server_url}/DefaultCollection
    Token: {paste your personal token here}
  5. Now you should be able to list all build tasks
    tfx build tasks list
  6. Assuming the directories with build tasks exists in current working directory we can easily upload them one by one running following command
    tfx build tasks upload --task-path .\DeployClickOnce
  7. Finally we logout from the server
    tfx logout

That’s it. All of the rest regarding creating and versioning build tasks stays the same.