Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild custom task "Hello World" walkthrough

Can someone write (or link to) a walkthrough that explains exactly how to create a custom MSBuild task and run it during a build? I'm looking for a custom task that inherits from Microsoft.Build.Utilities.Task and does only this:

public override bool Execute()
{
    Log.LogMessage("Hello world!");
    return true;
}

(I've been working on this for hours and keep getting the "The [whatever] task was not found. Check the following" message. I think I must be missing an essential step somewhere. If there's a clear tutorial I can follow, perhaps I'll figure out where I'm falling short.)

like image 549
Ryan Lundy Avatar asked Mar 02 '11 16:03

Ryan Lundy


People also ask

How do I run MSBuild task?

To execute a task in an MSBuild project file, create an element with the name of the task as a child of a Target element. If a task accepts parameters, these are passed as attributes of the element. Tasks can also return information to the project file, which can be stored in items or properties for later use.

Which is the initial step needed when using the MSBuild at the command prompt?

Build the targettargets file. Run MSBuild from the Developer Command Prompt for Visual Studio to build the HelloWorld target defined above. Use the -target or -t command-line switch to select the target.

What is inline task?

Inline user tasks are extensions of regular user tasks. Each inline user task implements a specific interface that is implicitly defined by what is exposed to it.


2 Answers

Are you declaring your custom task in your MSBuild project file? You need a line like this:

    <UsingTask AssemblyFile="C:\PathTo\MyTasks.dll" TaskName="MyTasks.HelloWord" />

Then MSBuild can execute your task.

like image 166
Carl Raymond Avatar answered Oct 20 '22 18:10

Carl Raymond


See

  1. Best Practices For Creating Reliable Builds section Creating Custom Tasks.
  2. THE CUSTOM MSBUILD TASK COOKBOOK from Bart De Smet
like image 29
Sergio Rykov Avatar answered Oct 20 '22 19:10

Sergio Rykov