CI/CD build pipeline for .NET solutions using Cake2 – Azure Devops

In a previous article Build .NET solutions/projects using cake 2 I described how you can build a .NET solution using cake 2. In this tutorial I will explain how you can create your continuous integration pipeline to build your projects automatically with cake 2 and a build agent.

You should first store your project on a git repository. For the purposes of this demo I will choose Azure Devops. I first clone the repository and add the appropriate code. Then I push back to the remote.

Git commands:

git add
git commit -m "added code"
git push

Then under main branch the src folder will be located. In this folder the code is placed.

The second step is to create the pipeline and store it in the repository. Press new pipeline and then select your Azure Repos Git.

Then choose the starter pipeline on which we will add some tasks.

The code for the pipeline is just a simple powershell script that will execute the cake build command as we examined on the previous article.

trigger:
- main

pool:
  vmImage: ubuntu-latest
steps:

- task: PowerShell@2
  displayName: Build step using cake
  inputs:
    targetType: 'inline'
    script: 'dotnet cake'
    workingDirectory: '$(Build.SourcesDirectory	)/src/'

When I tried to build my application although the procedure started, I got an error about the targeting SDK.

You can resolve this by specifying your requested DotNet version.

- task: UseDotNet@2
  displayName: Use .NET 6
  inputs:
    version: '6.0.x'
    includePreviewVersions: true

Finally the build will be successful.

The final pipeline will be the below:

trigger:
- none

pr: none

pool:
  vmImage: ubuntu-latest
steps:

- task: PowerShell@2
  displayName: install cake tool
  inputs:
    targetType: 'inline'
    script: 'dotnet tool install Cake.Tool --version 2.0.0 --global'

- task: UseDotNet@2
  displayName: Use .NET 6
  inputs:
    version: '6.0.x'
    includePreviewVersions: true

- task: PowerShell@2
  displayName: Build step using cake
  inputs:
    targetType: 'inline'
    script: 'dotnet cake'
    workingDirectory: '$(Build.SourcesDirectory)/src/'

One Reply to “CI/CD build pipeline for .NET solutions using Cake2 – Azure Devops”

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.