· Jun Yuan · DevOps  · 2 min read

Fixing Windows Service DevOps Artifact Issue

Learn how to resolve file structure issues in DevOps pipelines for Windows Service applications based on .NET 8.0 by compressing and extracting build artifacts.

Fixing Windows Service DevOps Artifact Issue

When working with Windows Service applications based on .NET 8.0 in a .NET Core environment, you might encounter issues with file structure changes during the DevOps pipeline process. This article explains the problem and provides a solution.

The Problem

While building and packaging a Windows Service application using Azure DevOps, I noticed that the runtimes directory’s file structure was altered when downloading the build artifacts in the Release pipeline. This caused the application to fail during deployment.

The issue occurred because the build artifacts were not compressed during the packaging step. Without compression, the file structure was modified during the artifact download process.

The Solution

To resolve this issue, I updated the pipeline to compress the build artifacts during the packaging step. Additionally, during deployment, I ensured that the compressed artifact was manually extracted and used to overwrite the existing files.

Steps to Fix the Issue

  1. Modify the Build Pipeline:

    • In the DotNetCoreCLI@2 task, enable the Zip published projects option during the publish step. This ensures that the build artifacts are automatically compressed into a .zip file.
  2. Update the Release Pipeline:

    • Add an Extract files task to the Release pipeline to extract the compressed artifact. This step ensures that the files are properly extracted to the deployment directory.
  3. Verify the Deployment:

    • After extracting the files, verify that the runtimes directory and other file structures remain intact.
    • Test the deployed application to ensure it works as expected.

Example YAML for Compression

Below is an example of how you can modify your Azure DevOps YAML pipeline to enable compression during the DotNetCoreCLI@2 publish step:

- task: DotNetCoreCLI@2
  inputs:
    command: 'publish'
    publishWebProjects: false
    zipAfterPublish: true
    arguments: '--configuration Release --output $(Build.ArtifactStagingDirectory)'

Deployment Script for Extraction

During deployment, you can use an Extract files task in the Release pipeline. Below is an example configuration:

- task: ExtractFiles@1
  inputs:
    archiveFilePatterns: '$(System.DefaultWorkingDirectory)/build-artifact.zip'
    destinationFolder: '$(System.DefaultWorkingDirectory)/extracted'
    cleanDestinationFolder: true

Conclusion

By compressing the build artifacts and ensuring proper extraction during deployment, you can avoid file structure issues in the DevOps pipeline. This approach ensures that your Windows Service application based on .NET 8.0 is deployed correctly and functions as expected.

If you encounter similar issues, consider reviewing your pipeline configuration and ensuring that artifacts are handled in a way that preserves their integrity.

Back to Blog

Related Posts

View All Posts »