{{announcement.body}}
{{announcement.title}}

Enabling CI-CD and Generating MSI Installations

DZone 's Guide to

Enabling CI-CD and Generating MSI Installations

In this series, we will demonstrate about the capabilities of Azure DevOps for CI-CD in software management.

· DevOps Zone ·
Free Resource

In this blog series, We will demonstrate the capabilities of Azure DevOps for CI-CD in software management.

Following points will be addressed in the document:

  • Basic CI-CD flow with C# software in Azure DevOps service
  • Generation of MSI installation with “WIX” package installation
  • “Out of the box” tasks in the azure pipeline to schedule timely releases, email the artifacts, generate code coverage and create GitHub release

Technical Specs

We will require some basic hands-on knowledge on the following items:

  • XAML and Wix Installer
  • Azure DevOps
  • Basic CD-CI knowledge for C# software and git

Prerequisite

We will require access to the following items:

  • Microsoft Azure Cloud
  • GitHub repository with C# Code

High-Level Design

There are so many discussions around automation and DevOps going on over the past few years. From my point of view, one of the most charming features of DevOps is you can deploy and automate the whole process.

Here is the basic flow of CD using Git and Azure DevOps services,

A screenshot of a cell phone

Description automatically generated

For Azure DevOps to be incorporated in the software, similar to any cloud CD solution we need to drive the pipeline through a single file(azure-pipeline.yml in our case).

There are the following items which are useful in the whole pipeline:

  • Stage: showcases the information on which type of pipeline is being executed. E.g: Dev build or Release build
  • Trigger: enables if the pipeline depends on any git branch or any package of a git branch
  • Variables: once defined in the top, can be used across the pipeline in the single run. Useful for generating incremental number in the release.
  • Pool: adding the information on the location or image on software to be executed.
  • Steps: provides the clarity on the pipeline on which cycles does the code needs to go through before final MSI generation
  • Task: various activity which needs to be performed on the software is assigned under task. E.g: running a batch script, MSI installation, etc.
  • Schedules: In case of time-based or scheduled releases, this can be used to generate a cron expression or  user-defined scenario                 
code block
code block

The following activities are done in the above sample application.

  1. Triggers when any developers check in the code in the master branch
  2. Generating automated incremental release number and stores it in variable
  3. Downloads the latest code from Git Branch
  4. C# Nuget Restore command to download the packages
  5. Building the solution with MSBuild Command via the sln file
  6. Download the Test Case installation package and Code Coverage generation package
  7. Execute the Test Cases via VSTest Suite task and generate the results
  8. Publish the Code Coverage and Test Case result.
  9. Run the MSI Installation Command line to generate exe via the “Wix” package.
  10. Upload the MSI package in an artifact
  11. (Optional) Create a Git Release for the code and share the Release Notes.
  12. (Optional) Email the link of the artifact via the “send email” task.

We can define cron expression if we need to release the build in a specific timeline.

Here is sample example to be executed daily at 4 PM and 12 PM EST and will build from the master branch

code block

GitHub Release

We can release the code build from the pipeline after successful execution and share the release notes to others via email. Following is the task which can be added after the publishing of the artifact.

code block

WIX Installation

There are many ways of generating MSI packages for Windows applications. E.g: Vdproj, Wix
Definition of MSI: It is an installer package file format used by Windows. Its name comes from the program’s original title, Microsoft Installer, which has since changed to Windows Installer. MSI files are used for installation, storage, and removal of programs. The files are contained in a package, which is used with the program’s client-side installer service, an an.EXE file, to open and install the program.

We will showcase the power of “WIX” services in the blog to generate the MSI.

Here is a basic example of the sample WIX file which needs to be present in the source code:

sample WIX files

All the tags present in the xml file and explanations for the same can be found in the below link.

https://wixtoolset.org/documentation/

Once we run the below mentioned commands for Wix from the pipeline, it will generate the MSI and publish the same.

  • “%WIX%bin\candle” *.wxs -o obj\
  • “%WIX%bin\light” obj\*.wixobj -o bin\CommandLineInstaller.msi

Explanation and Binaries of the above are given in the below link.

https://github.com/wixtoolset/wix3

Conclusion

In the above blog, we have showcased the capabilities of Azure DevOps for enabling CD and CI.

Many other things can be incorporated with the pipeline and we can use the environment and test artifact generation services to handle the releases more efficiently.

Topics:
azure, c#, devops, msi, tutorial, windows ( 4 ), wix

Published at DZone with permission of Aritra Nag . See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}