Ads2

Saturday, 2 August 2025

Azure DevOps CI/CD Pipeline for .NET MAUI App

 This guide walks you through setting up a Continuous Integration (CI) and Continuous Deployment (CD) pipeline for a .NET MAUI application in Azure DevOps.


Prerequisites

  • .NET MAUI project in a Git repository (Azure Repos, GitHub, etc.)

  • An Azure DevOps organization and project

  • .NET 6+ SDK installed on the build agent (or use Microsoft-hosted agents)

  • (Optional) Signing certificates & provisioning profiles (for iOS/Android deployment)


Step 1: Set Up Your Repository

Ensure your .NET MAUI project is in a Git repository (Azure Repos, GitHub, Bitbucket, etc.).


Step 2: Configure the Build Pipeline (CI)

Option A: YAML Pipeline (Recommended)

  1. Navigate to Pipelines → Pipelines → New Pipeline in Azure DevOps.

  2. Select your repository.

  3. Choose "Starter pipeline" or select .NET MAUI template if available.

  4. Replace the YAML with the following:

yaml
trigger:
  branches:
    include:
      - main
      - develop

pool:
  vmImage: 'windows-latest' # For Windows builds (required for .NET MAUI)

variables:
  buildConfiguration: 'Release'
  dotNetVersion: '7.0.x' # Adjust based on your .NET version

steps:
- task: UseDotNet@2
  displayName: 'Install .NET SDK'
  inputs:
    version: $(dotNetVersion)

- task: DotNetCoreCLI@2
  displayName: 'Restore NuGet Packages'
  inputs:
    command: 'restore'
    projects: '**/*.csproj'

- task: DotNetCoreCLI@2
  displayName: 'Build .NET MAUI App'
  inputs:
    command: 'build'
    projects: '**/*.csproj'
    arguments: '--configuration $(buildConfiguration) -f net7.0-android' # Adjust target (android/ios)

- task: DotNetCoreCLI@2
  displayName: 'Publish .NET MAUI App'
  inputs:
    command: 'publish'
    projects: '**/*.csproj'
    arguments: '--configuration $(buildConfiguration) -f net7.0-android /p:AndroidSigningKeyPass=$(AndroidKeyPass) /p:AndroidSigningStorePass=$(AndroidStorePass)' # Optional signing

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact'
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

Option B: Classic UI Pipeline

  1. Create a new pipeline → Select "Use the classic editor".

  2. Choose your repository.

  3. Select ".NET Desktop" template.

  4. Add the following tasks:

    • Use .NET Core (Install correct SDK version)

    • NuGet restore

    • .NET Core Build (--configuration Release -f net7.0-android)

    • .NET Core Publish (Optional: Add signing arguments)

    • Publish Artifacts


Step 3: (Optional) Set Up Signing for Android/iOS

Android Signing

  1. Add Secure Variables in Pipeline → Library → Variable Groups:

    • AndroidKeyStore (Upload .keystore file as a Secure File)

    • AndroidKeyAlias

    • AndroidKeyPass (Mark as secret)

    • AndroidStorePass (Mark as secret)

  2. Modify YAML to include signing:

    yaml
    - task: AndroidSigning@3
      inputs:
        apkFiles: '**/*.apk'
        apksignerKeystoreFile: '$(AndroidKeyStore)'
        apksignerKeystorePassword: '$(AndroidStorePass)'
        apksignerKeyAlias: '$(AndroidKeyAlias)'
        apksignerKeyPassword: '$(AndroidKeyPass)'

iOS Signing

  1. Import Certificates into the build agent:

    yaml
    - task: InstallAppleCertificate@2
      inputs:
        certSecureFile: 'YourCert.p12'
        certPwd: '$(iOSCertPassword)'
  2. Provisioning Profile:

    yaml
    - task: InstallAppleProvisioningProfile@1
      inputs:
        provisioningProfileLocation: 'secureFiles'
        provProfileSecureFile: 'YourProfile.mobileprovision'

Step 4: Set Up Release Pipeline (CD)

  1. Navigate to Pipelines → Releases → New Pipeline.

  2. Add Artifact (Select the build pipeline output).

  3. Add Stages (e.g., DevQAProduction).

  4. Deployment Tasks:

    • Android: Use App Center Distribute or Google Play Release.

    • iOS: Use App Center or Apple App Store Release.

Example: App Center Deployment

yaml
- task: AppCenterDistribute@3
  inputs:
    serverEndpoint: 'AppCenter'
    appSlug: 'YourOrg/YourApp'
    appFile: '**/*.apk'
    releaseNotesOption: 'input'
    releaseNotesInput: 'Automated release'

Step 5: Run & Monitor Pipeline

  • Trigger manually or via Git push.

  • Check logs for failures.

  • Test the deployed app in App Center/TestFlight/Play Store.


Conclusion

You now have a fully automated CI/CD pipeline for your .NET MAUI app in Azure DevOps

Next Steps:

  • Add unit tests (DotNetCoreCLI@2 test task).

  • Configure environment-specific variables.

  • Set up branch policies for PR validation.

No comments:

Post a Comment

Fantasy Cricket Mobile App in .NET

  1. Planning the Fantasy Cricket App Key Features to Include: User registration and authentication Player selection interface Match schedul...