Question

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. :-)

Was it helpful?

Solution 2

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! :)

OTHER TIPS

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. =)

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