Click here to Skip to main content
15,608,404 members
Articles / DevOps / Continuous Integration
Posted 13 Nov 2018


7 bookmarked

Deploying Windows Service using Azure Pipeline

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
13 Nov 2018CPOL4 min read
Setting up automated build and deployment for Windows service using Azure Pipeline


This article helps you to understand how to setup automated build and deployment from GIT repository using Azure Pipeline. Build, test, and deploy with CI/CD that works with any language, platform, and cloud. Connect to GitHub or any other Git provider and deploy continuously.

Create Project in GIT Repository

Create a win service project in Visual Studio and configure the git repository to push the code into GIT. Once the code pushed into GIT, the build will kick start automatically.

Image 1

Create an Organization in Azure DevOps

We need to create organization and project in Azure devops in order to start using Azure Pipeline. The below Microsoft document shows the steps how to create an organization with a personal Microsoft account or a work or school account. Use your work or school account to automatically connect your organization to your Azure AD.

Follow the above link to complete the organization setup and create the project. Once this step is completed, we are ready to setup our first build pipeline.

Setup the Build Pipeline

I created a project named Main. Go to the overview page of the project and then choose Pipelines -> Builds -> New -> New build pipeline

Image 2

Image 3

New window will be opened to choose source branch, repository and the source branch for build. Select the options as below according to your project.

Image 4

Choose the .NET Desktop template since I can make use of most of the pre-defined pipeline steps which fit for my windows service build, enter the name of the pipeline and choose any given Microsoft hosted agent or you can choose your own job (Default - No agents). For this example, I am using the Microsoft hosted agent (Hosted VS2017) which is a good fit for my build. To understand more about agent pools, click here.

Image 5

Image 6

.NET Desktop template has the list of build_pipeline5.JPG default jobs, for this project, I just leave with the default values for Nuget, Nuget restore, Build solution and VsTest tasks. If you don't want any of these tasks, you can just select the specific task under the agent and remove it.

Choose the Publish symbols path task and enter the details as below and leave the other fields with the default values.

Image 7

Choose the Copy Files task and enter the information as below and leave the other fields with the default values.

Image 8

Choose the Publish Artifact task, enter the information as below and leave the other fields with the default values.

Image 9

Then click Save.

Get the status batch (refer to the section Get the status batch in this Microsoft documentation) and add into the file in github branch as below.

Image 10

Choose the trigger menu and select Enable continuous integration option and save it.

Image 11

First build will be queued and started. Build is triggered and succeeded. Now we automated the build using Azure Pipeline. Hereafter, whenever there is a change in the code, build will be triggered automatically.

Image 12

Create Deployment Groups and Provision Agents 

To access the target server to deploy application, we need to create deployment group. Deployment group is a logical set of deployment target machines that have agents installed on each server.

Follow this link to create deployment group and provision agents in the VM.

In this stage, deployment group is created in Azure DevOps and the agent installation script is run successfully in the target machine. Next, we proceed to setup the release pipeline.

Setup the Release Pipeline 

Follow the below steps to setup the release pipeline.

  1. Choose release pipeline -> New -> New release pipeline -> Select template -> Choose Empty Job

    Image 13

  2. Select artifact task and fill in the information as below and click add. This is where we configure the build artifact as the source for the release.

    Image 14

  3. Enable the continuous release as below. It is applicable mostly for SIT/UAT environments. For production environment, it will not be the case as we deploy based on schedules.

    Image 15

  4. Select view stage tasks and add/modify the below tasks in sequence. Refer to the below screenshots. Select stage task and add a deployment group job. Once added, select the deployment group job and update the information as below and leave other fields with the default values.

    Image 16

  5. Select the Agent job and update the information as below.

    Image 17

  6. Install WinRM File Copy task template from the market place and add this task by clicking Add a task to Agent job.

    Image 18

    Image 19

    • DisplayName can be any name
    • Source is the path where the artifact resides
    • Machine is the Virtual Machine IP (Target server IP)
    • Enter the VM Admin Login and Password
    • Virtual machine folder path where you want to host your windows service
  7. Add Command Line task and update the template as below:

    Image 20

    This SC commands helps to stop, delete, install and start the windows service in the Virtual Machine. You can modify the scripts according to your needs.

  8. Click Save and choose Release to start deploying the windows service to the target server.

Here you go! Successfully deployed the win service into the virtual machine.

Image 21

Points of Interest

It's interesting when I started exploring Azure devops, it makes life easy :). Lot more to learn and make use of it in your projects.

This article makes you understand how to setting up the CI/CD pipeline. You can experiment other futures of Azure DevOps and strengthen your DevOps skills .

Happy learning! Any improvements on this article, please comment below.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Technical Lead
Singapore Singapore
11+ Years of IT experience in Application software development and having vast experience in Enterprise applications integration, Desktop, Client Server, Web and SOA architecture.
Experienced lead developer and consultant, A Microsoft Certified Solutions Expert and a Certified Professional Scrum Master.

Comments and Discussions

QuestionCouldn't get it to work Pin
Member 149594232-Mar-22 19:44
Member 149594232-Mar-22 19:44 
QuestionWindows Service on Pipeline for other environments Pin
TMags21-May-21 8:56
TMags21-May-21 8:56 
QuestionWindows service with a UI Pin
George Hendrickson21-May-19 7:42
professionalGeorge Hendrickson21-May-19 7:42 
I have a windows service that I developed that I created a UI for to manage the service and view logging information with. How do you deploy a windows service with Azure DevOps that has a separate UI project and make it create shortcuts on the desktop screen for all users?
QuestionError - The RPC server is unavailable. Cmd.exe exited with code '1722' Pin
Nitin Kadam26-Feb-19 8:13
Nitin Kadam26-Feb-19 8:13 
AnswerRe: Error - The RPC server is unavailable. Cmd.exe exited with code '1722' Pin
Prabakaran Rajendran17-Mar-19 19:28
professionalPrabakaran Rajendran17-Mar-19 19:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.