2

I have a library of custom MSBuild tasks which I edit quite regularly, refactoring code, adding new tasks and removing old, defunct ones. It's become a pain to edit the .Targets file to sync with what is actually in the library, so I was wondering, what would be the best way to automate this?

I would like a solution that runs after the library has built successfully, so that I don't get any nasty errors when trying to call my custom tasks from other projects.

I do have a few ideas about how to do this, but I'd like to see what others come up with first. :-)

2 Answers 2

1

You may have a separate .targets file containing only references to your tasks. From one side link it in your main .targets file. From the other overwrite it executing some another "master" custom task in your AfterBuild target of the tasks solution. This "master" task will get all classes implementing ITask from newly built assembly and write them to .targets file.
But to be honest this looks like an overkill to me. You have to edit your .targets file anyway to get use of your new tasks. Writing such a "master" task and supporting it may take you more time.

I may fantasize on several more automated solutions, but considerations of "time invested"/"time saved due to automation" stop the flight of my imagination. =)

Sign up to request clarification or add additional context in comments.

2 Comments

I've found a solution using PowerShell, assembly reflection, and XML. I run the PowerShell script in the AfterBuild target of the project, and the .Targets file is created as expected. This does not strike me as an elegant solution, though ... Any thoughts about this, or alternatives? =)
You can move the .Targets you created with Powershell and reflection in a (network) path which any developer can access. Then, in your projects build script you always reference your "master" .Targets file. As for using Powershell and reflection, this doesn't sound inelegant to me. You may also use xml comments instead of reflexion but this would need more work.
0

Well, I've found a nicer way to achieve this by using MSBuild Community Task's TaskSchema task:

<TaskSchema Assemblies="@(MyTaskAssembly)" OutputPath="%(MyTaskAssembly.RootDir)%(MyTaskAssembly.Directory)" CreateTaskList="true" IgnoreMsBuildSchema="true" Includes="Microsoft.Build.Commontypes.xsd"/> 

I simply ensure that I've imported the MSBuild.Community.Tasks.Targets file, create an ItemGroup named MyTaskAssembly containing all of my task assemblies (shocker), then stick the above task call in the AfterBuild target of my project. Sweet! :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.