Automating local .NET service deployment

As part of implementing a continuous integration/deployment pipeline for our team, a recent task involved enabling automated deployment of a .NET Windows service for integration testing purposes. As it stands, integration testing targets are installed locally on the CI server - not ideal, but good enough for us at the comment.

Below is a script I concocted deploy .NET Windows services once the automated build/unit testing steps have completed successfully. Usage is quite simple:

Powershell C:\Scripts\deployservice.ps1 -serviceName "My Super Service" -serviceExecutable "mysuperservice.exe" -sourceFolder "C:\Build\TheSuperSolution\MySuperService\bin\Release" -destinationFolder "C:\Staging\MySuperService"

The parameters are quite straight forward:

  • -serviceName: This is the actual service name.
  • -serviceExecutable: The name of the service executable (.exe) file.
  • -sourceFolder: The folder where the build output resides. The script will copy the entire content of this folder to the staging folder.
  • -destinationFolder: The staging folder where the service must be installed to and be running from.

And the script: