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.
![](https://i0.wp.com/blog.geralexgr.com/wp-content/uploads/2022/01/image-13.png?resize=961%2C111&ssl=1)
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.
![](https://i0.wp.com/blog.geralexgr.com/wp-content/uploads/2022/01/image-14.png?resize=362%2C275&ssl=1)
The second step is to create the pipeline and store it in the repository. Press new pipeline and then select your Azure Repos Git.
![](https://i0.wp.com/blog.geralexgr.com/wp-content/uploads/2022/01/image-15.png?resize=667%2C212&ssl=1)
Then choose the starter pipeline on which we will add some tasks.
![](https://i0.wp.com/blog.geralexgr.com/wp-content/uploads/2022/01/image-16.png?resize=600%2C546&ssl=1)
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.
![](https://i0.wp.com/blog.geralexgr.com/wp-content/uploads/2022/01/image-17.png?resize=980%2C503&ssl=1)
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.
![](https://i0.wp.com/blog.geralexgr.com/wp-content/uploads/2022/01/image-18.png?resize=915%2C866&ssl=1)
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/'