Robo Kiwi

  • Blog
  • Wiki
  • GitHub

Contents

Wiki / .NET / MSBuild / Async Tasks
1 min read

Async Tasks

Using async code in custom MSBuild tasks

Async Tasks

You can use async in MSBuild tasks using a pattern like this:

public class MyCustomTask : Task {

    public override bool Execute()
    {
        return ExecuteAsync().GetAwaiter().GetResult();
    }

    protected async Task<bool> ExecuteAsync()
    {
         // Async / await code goes here
         
         // Return the result
         return true;
    }
}

Here, the default Task Execute implementation simply calls an async method (in a synchronous manner obviously).

This allows you to consume APIs that expose async methods, as the async/await becomes more pervasive.

  • .NET
    • Testing
    • .NET Patterns
    • Asynchronous Programming
    • MSBuild
  • Microsoft Dynamics
  • Apps & Tools
  • Data & Databases
    • SQL
  • Debugging
  • JavaScript
  • Microsoft Office
  • Practices
  • Principles & Theory
  • Scripting
    • PowerShell
  • Security
  • Source Control
  • Web Technologies
    • JavaScript
    • React
  • Windows
Copyright © David Moore 2021

Netlify badge Built with Hugo