DevOps is a complicated discipline, so when we as developers have to set up a build pipeline in Azure Devops we are sometimes in deep water.
Thats why I made this yml template that I can copy from whenever I need to build a .net 6 project:
trigger: - main pool: name: Azure Pipelines vmImage: 'windows-2019' variables: buildConfiguration: 'Release' steps: - task: UseDotNet@2 displayName: 'Use .NET Core 6' inputs: version: 6.0.x - task: DotNetCoreCLI@2 displayName: Restore inputs: command: restore projects: '**/*.csproj' - task: DotNetCoreCLI@2 displayName: Build inputs: projects: '**/*.csproj' - task: DotNetCoreCLI@2 displayName: Publish inputs: command: publish publishWebProjects: false projects: '**/*.csproj' arguments: '--configuration release --output $(build.artifactstagingdirectory) /property:PublishWithAspNetCoreTargetManifest=false' zipAfterPublish: false - task: PublishBuildArtifacts@1 displayName: 'Publish Artifact' inputs: ArtifactName: myproject
I name the file “azure-pipelines.yml” and place it in the root of my project:
When the pipeline has run it creates an artifact that can be deployed:
SO WHAT DOES EACH SECTION DO?
|trigger||Determines which branch will trigger the pipeline. Is used for continuous deployment|
|pool||Determines the server that it uses as build platform. Use windows-2019, not ubuntu if you wish to build .net core 6 code|
|variables||Sets up build variables|
|task: UseDotNet@2||Tells the build to use .net core 6 when building. If you leave out this step, it will build using .net core 3.1 instead.|
|DotNetCoreCLI@2/Restore||Gets NuGet packages|
|DotNetCoreCLI@2/Build||Builds the project|
|DotNetCoreCLI@2/Publish||Copies the files to a folder.|
publishWebProjects will determine what to copy. If true, it will copy web projects
zipAfterPublish determines if the out should be zipped.
property:PublishWithAspNetCoreTargetManifest=false will copy your NuGet dll’s along with the dlls of the project
|PublishBuildArtifacts@1||Creates an artifact that can be used by your release pipeline|
This is just an introduction to DevOps. I hope that the file will give you a hint of what to do before panicking if you are given the task of setting up your own build and release pipelines.
MORE TO READ:
- Force ‘dotnet publish’ to publish dependencies using PublishWithAspNetCoreTargetManifest by Benjamin Day
- Build, test, and deploy .NET Core apps from Microsoft
- .NET Core CLI task by Microsoft
- Publish Build Artifacts task by Microsoft