Generally windows services are deployed by creating an msi installer. It is possible to deploy msi via VSTS/TFS release management using the extension available in the marketplace. Packaging the windows as non msi would give opportunity to have more control on the configurations etc, when deployment and let’s see how to package a windows service and then get it deployed via VSTS/TFS release management.
Most important point is how to get the apply the configuration parameters for a windows service at deployment depending in the target and how to tokenize the configuration in the builds. Windows service would contain a app.config file and to transform an app.config you can add say for example app.release.config with xdt transformation tags.
To transform this sort of a config in the VSTS builds you can use XDT transform task coming with marketplace extension. You can use syntax of app.release.config => app.config to get the transformation happened from build and applied to app.cofig which is getting packaged. If you have multiple config files this task can tranfrom all and you can add additional transform entries as new lines in Transformations field.
You can build and package the windows service project as NuGet package and use it in the release as discussed in “Using NuGet Packages as VSTS Release Artifact Source”, or you can use the build drop as default pattern in VSTS/TFS builds.
To enable replacing of tokens applied in the config file with the transformation discussed above at the deployment time with the variable values setup in the release definition, you can use replace tokens task available in the extension in marketplace.
To deploy the windows service a good extension is available in marketplace having few tasks. It has stop and start tasks as well as create/update windows service task. Stop service task is useful to stop the service before start the deployment. It can be set to continue on error to prevent any errors in initial deployment if the service is not available or in an event the service is already stopped.
You have to use the copy file task to copy the files from artifacts drop extracted location to a designated path of the windows service after stopping the service. The the create windows service task can be used to update the service if it is already available or if it is not available to create it.
The you can use the start windows service task to start the service after deployment. You can group all these tasks to a task group and use it as a single task to enable usage with multiple release definitions to enable windows service deployments.