kakha
kakha

Reputation: 135

ASP.NET Core application as Windows Service CI/CD Pipeline

I have an ASP.NET Core application configured as Windows Service.

I Need to deploy my app using VSTS pipeline on Windows machine, but cannot find out how to do that with windows service.

Any help will be appreciated :)

Upvotes: 2

Views: 1174

Answers (1)

Colin B
Colin B

Reputation: 316

Firstly you'll want a build pipeline that emits the built code into a package (i.e. .NET core tasks to get your dependencies, build your code and publish your code. This code should be placed into $(Build.ArtifactStagingDirectory) which then is published into a drop. All this is pretty much standard .NET core build pipeline stuff from the out of box template. In addition to this you'll need a copy task that will copy a powershell file or files (which I'll talk about later) into $(Build.ArtifactStagingDirectory).

It is the release pipeline that will do the deployment where you'll need to do something a little different as I dont know of any marketplace tasks to really help you here. What we really need to do in the Release pipeline is create a deployment that follows some of the steps (4-7) in this bit of documentation (https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-2.1) as it details the steps to install a ASP.NET Windows Service.

What I suggest here is that you write steps 4-7 in either one or several powershell scripts and commit these into your codebase and process these via the copy task as I mentioned earlier.

In the release it will download from your build artifact the published service code and the powershell file(s) it needs to deploy the service. All the release pipeline need then do is copy the service exe code into the service deployment directory (in the example steps it uses c:\svc so copy the files to here). Then simple execute a powershell task (or tasks) on the scripts above so that the agent runs these steps to get the service installed correctly.

The above assumes using a private pipeline agent locally installed on the server you are deploying to. If you want to deploy the same service to many servers you should look at deployment groups for your release pipeline, but the steps above should all work the same. just with all the tasks in a Deployment Group Phase rather than the usual Agent Phase.

Hope that helps.

Upvotes: 1

Related Questions