Create a windows service deployment task in TFS

The following tutorial will provide guidelines to create a complete TFS build and deploy task for a windows service based on Topshelf service.

  1. Create a topshelf service (See how to create a simple topshelf service post)
  2. Install windows service release task from the market place

  1. Create a new build
  2. Add the following tasks

  1. Now select Stop windows service, identify the name of your service, machines, and login infos for the target machines. Note that you need to have user with admin privileges on all the target deployment machines.
  2. Select the copy files task And set source folder to

$(build.sourcesdirectory)\{Your-ProjectPath}\bin\{Your current build config}

Set the target folder to a secured shared network drive that is accessible with owner rights to the user your services runs on


  1. Now for the install topshelf service, use the pat specified in step 6 for Topshelf exe paths. Specify the same machines and login as the stop window service task
  2. Configure the start windows service task exactly the same as the stop service task configured earlier
  3. Now on each of the machines you configured to deploy the service you need to make sure of the following:
    1. User configured in your tfs task is an administrator of this machine.
    2. User configured in your tfs task has owner rights to the service network folder
    3. Computer is allowed for remoting. To do that, open a powershell prompt (RUN AS ADMINISTRATOR) and execute the following cmdlet:

Enable-PSRemoting -Force

That’s it! You should be able to deploy your windows service from an automated tfs task.

Submit a Comment

Your email address will not be published. Required fields are marked *

Share This