Sharpliner 0.3.2

.NET 5.0
There is a newer version of this package available.
See the version list below for details.
dotnet add package Sharpliner --version 0.3.2
NuGet\Install-Package Sharpliner -Version 0.3.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sharpliner" Version="0.3.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sharpliner --version 0.3.2
#r "nuget: Sharpliner, 0.3.2"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Sharpliner as a Cake Addin
#addin nuget:?package=Sharpliner&version=0.3.2

// Install Sharpliner as a Cake Tool
#tool nuget:?package=Sharpliner&version=0.3.2

Sharpliner is a .NET library that lets you use C# for Azure DevOps pipeline definition. Exchange YAML indentation problems for the type-safe environment of C# and let the intellisense speed up your work!

Getting started

All you have to do is reference our NuGet package in your project, override a class with your definition and build the project! Dead simple!

For more detailed steps, check our documentation.


// Just override prepared abstract classes and build the project, nothing else is needed!
class PullRequestPipeline : SingleStageAzureDevOpsPipelineDefinition
    // Say where to publish the YAML to
    public override string TargetFile => "azure-pipelines.yml";
    public override TargetPathType TargetPathType => TargetPathType.RelativeToGitRoot;

    public override AzureDevOpsPipeline Pipeline => new()
        Pr = new PrTrigger("main"),

        Variables =
            // YAML ${{ if }} conditions are available with handy macros
            // that expand into the lengthy expressions such as comparing branch names.
            // We even have "else" :)
                .Variable("DotnetVersion", "6.0.100")
                .Variable("DotnetVersion", "5.0.202"),

        Jobs =
            new Job("Build")
                Pool = new HostedPool("Azure Pipelines", "windows-latest"),
                Steps =
                    // Many tasks have helper methods for shorter notation
                    DotNet.Install.Sdk("$(DotnetVersion)").DisplayAs("Install .NET SDK"),

                    // You can also specify any pipeline task in full
                    Task("DotNetCoreCLI@2", "Build and test") with
                        Inputs = new()
                            { "command", "test" },
                            { "projects", "src/MyProject.sln" },

                    // If statements supported almost everywhere
                        // You can load the script contents from a .ps1 file and inline them into the YAML
                        // This way you can keep writing scripts with syntax highlighting and IDE support
                        .Step(PowerShell.FromResourceFile("New-Report.ps1", "Create build report")),

Sharpliner features

Apart from the obvious benefits of using static type language with IDE support, not having to have to deal with indentation problems ever again, being able to split the code easily or the ability to generate YAML programatically, there are several other benefits of using Sharpliner.


One of the best things when using Sharpliner is that you won't have to go the YAML reference every time you're adding a new piece of your pipeline. Having everything strongly typed will make your IDE give you hints all the way!

Imagine you want to install the .NET SDK. For that, Azure Pipelines have the DotNetCoreCLI@2 task. However, this task's specification is quite long since the task does many things:

# .NET Core
# Build, test, package, or publish a dotnet application, or run a custom dotnet command
- task: DotNetCoreCLI@2
    #command: 'build' # Options: build, push, pack, publish, restore, run, test, custom
    #publishWebProjects: true # Required when command == Publish
    #projects: # Optional
    #custom: # Required when command == Custom
    #arguments: # Optional
    #publishTestResults: true # Optional
    #testRunTitle: # Optional
    #zipAfterPublish: true # Optional
    #modifyOutputPath: true # Optional
    #feedsToUse: 'select' # Options: select, config
    #vstsFeed: # Required when feedsToUse == Select
    #feedRestore: # Required when command == restore. projectName/feedName for project-scoped feed. FeedName only for organization-scoped feed.
    #includeNuGetOrg: true # Required when feedsToUse == Select
    #nugetConfigPath: # Required when feedsToUse == Config
    #externalFeedCredentials: # Optional
    #noCache: false
    #restoreArguments: # Optional
    #verbosityRestore: 'Detailed' # Options: -, quiet, minimal, normal, detailed, diagnostic
    #packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg' # Required when command == Push
    #nuGetFeedType: 'internal' # Required when command == Push# Options: internal, external
    #publishVstsFeed: # Required when command == Push && NuGetFeedType == Internal
    #publishPackageMetadata: true # Optional
    #publishFeedCredentials: # Required when command == Push && NuGetFeedType == External
    #packagesToPack: '**/*.csproj' # Required when command == Pack
    #packDirectory: '$(Build.ArtifactStagingDirectory)' # Optional
    #nobuild: false # Optional
    #includesymbols: false # Optional
    #includesource: false # Optional
    #versioningScheme: 'off' # Options: off, byPrereleaseNumber, byEnvVar, byBuildNumber
    #versionEnvVar: # Required when versioningScheme == byEnvVar
    #majorVersion: '1' # Required when versioningScheme == ByPrereleaseNumber
    #minorVersion: '0' # Required when versioningScheme == ByPrereleaseNumber
    #patchVersion: '0' # Required when versioningScheme == ByPrereleaseNumber
    #buildProperties: # Optional
    #verbosityPack: 'Detailed' # Options: -, quiet, minimal, normal, detailed, diagnostic

Notice how some of the properties are only valid in a specific combination with other. With Sharpliner, we remove some of this complexity using nice fluent APIs:

    .DisplayAs("Install .NET " + parameters["version"]),

DotNet.Build("src/MyProject.csproj") with
    IncludeNuGetOrg = false,
    Timeout = TimeSpan.FromMinutes(20)

Useful macros

Some very common pipeline patterns such as comparing the current branch name or detecting pull requests are very cumbersome to do in YAML (long conditions full of complicated ${{ if }} syntax). For many of these, we have handy macros so that you get more readable and shorter code.

For example this YAML

${{ if eq(variables['Build.SourceBranch'], 'refs/heads/production') }}:
    name: rg-suffix
    value: -pr
${{ if ne(variables['Build.SourceBranch'], 'refs/heads/production') }}:
    name: rg-suffix
    value: -prod

can become this C#

    .Variable("rg-suffix", "-pr")
    .Variable("rg-suffix", "-prod")

Sourcing scripts from files

When you need to add cmd, PowerShell or bash steps into your pipeline, mainatining these bits inside YAML can be error prone. With Sharpliner you can keep scripts in their own files (.ps1, .sh..) where you get the natural environment you're used to such as syntax highlighting. Sharpliner gives you APIs to load these on build time and include them inline:

Steps =
    Bash.FromResourceFile("") with
        DisplayName = "Run post-build clean-up",
        Timeout = TimeSpan.FromMinutes(5),

Pipeline validation

Your pipeline definition can be validated during publishing and you can uncover issues, such as typos inside dependsOn, you would only find by trying to run the pipeline in CI. This gives you a faster dev loop and greater productivity.

Something missing?

This project is still under development and we probably don't cover 100% of the cases, properties and tasks. If you find a missing feature / API / property / use case, file an issue in project's repository - or even better - file a PR and we will work with you to get you going!

If you want to start contributing, either you already know about something missing or you can choose from some of the open issues. We are very responsive and will help you review your first change so that you can continue with something advanced!

Another way to start is to use Sharpliner to define your own, already existing pipeline. This way you can uncover missing features or you can introduce shortcuts for definitions of build tasks or similar that you use frequently. Contributions like these are also very welcome! In these cases, it is worth starting with describing your intent in an issue first.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Sharpliner:

Repository Stars
Use C# instead of YAML to define your Azure DevOps pipelines
Version Downloads Last updated
1.4.8 60 11/20/2022
1.4.7 728 10/28/2022
1.4.6 99 10/28/2022
1.4.5 149 10/18/2022
1.4.4 165 9/16/2022
1.4.3 160 9/7/2022
1.4.2 160 9/1/2022
1.4.1 157 8/31/2022
1.3.7 158 8/26/2022
1.3.6 182 8/14/2022
1.3.5 190 7/11/2022
1.3.4 206 5/13/2022
1.3.3 241 4/17/2022
1.3.2 187 4/3/2022
1.3.1 257 3/15/2022
1.3.0 196 3/13/2022
1.2.9 216 3/5/2022
1.2.8 200 2/26/2022
1.2.7 208 2/17/2022
1.2.6 2,482 2/14/2022
1.2.5 200 2/11/2022
1.2.4 182 12/15/2021
1.2.3 178 12/5/2021
1.2.1 1,461 11/28/2021
1.2.0 1,208 11/28/2021
1.1.2 5,316 11/23/2021
1.1.1 218 11/18/2021
1.1.0 210 11/15/2021
1.0.2 234 11/8/2021
1.0.0 286 11/6/2021
0.3.9 234 11/4/2021
0.3.8 220 11/1/2021
0.3.7 252 10/24/2021
0.3.6 297 10/20/2021
0.3.5 233 10/20/2021
0.3.4 233 10/17/2021
0.3.3 275 10/16/2021
0.3.2 237 10/14/2021
0.3.1 195 10/14/2021
0.3.0 237 10/14/2021
0.2.2 220 8/30/2021
0.2.1 240 8/22/2021
0.2.0 229 8/22/2021
0.1.1 340 7/24/2021
0.1.0 253 7/24/2021