Question

Is it possible to invoke other MSBuild tasks (CL, Link, Delete, MakeDir, etc.) from within a Custom (inline or non inline) Task which is being invoked via a MSBuild Project File? Something like:

<!-- In MSBuild File -->
<MyStrangeTask />

And in C# Code implementing "MyStrangeTask"

// After declaring class, properties, etc.
public override bool Execute()
{
    // Call other MSBuild Tasks here: CL, Link, MakeDir, etc.
}

Yes, it might be possible to duplicate functionality of some of the tasks (Delete, MakeDir, etc.) but why re-invent the wheel? Besides, tasks such as CL and Link would be time consuming to re-implement.

Why i need this?

i am writing a custom task which basically needs to do copying files, invoking CL preprocessor, etc. One may question the very design of such a "huge" task but let's just say some requirements force us to walk this "tedious" path.


EDIT: to emphasize the correct context of this question

This question is not from a design but a technical perspective.

Being a novice in this field, i just wish to know is this technically possible? If Yes, how? If Not, why not?

Was it helpful?

Solution

First of all you can find classes used for MSBuild tasks at MSDN. But you should note that it's explicitly written:

This API supports the .NET Framework infrastructure and is not intended to be used directly from your code

Also you can find example of such usage in this blog post.

So that is answer to what you asked, but maybe there is different solution that you need: You can break your task into many sub-tasks: output from first custom task is sent to MSBuild project that can be used by built-in tasks and output of built-in task sent into your second custom task and so on.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top