Dobkin's Place

Monday, February 26, 2007

Extending the build process – GacUtil task

As part of planning a daily build process I needed to register the current assembly to the GAC. I was Surprised to find that there is no such a task that came with the VS tasks kit. And I was event more surprised to not find such a task in the common extension tasks kit for MSBuild. So I said "This all mechanism is so easily extendable so why no write a task for my own to cover this issue? – and practice in writing MSBuild tasks in the way". So that's what I did.
I write some custom task called GacUtil which get two parameters:
Assemblies – a list of assemblies to work with.
Command – the operation that should be made on the assemblies, Install or Uninstall.

You can use the command by simply add the "using task" attribute in to your .proj file for example.

<UsingTask TaskName="CostumTasks.GacUtilTask" AssemblyFile="$(SolutionDir)\CostumTasks\bin\Debug\CostumTasks.dll" />

And call the task that way

<gacutiltask command="Install" assemblies="$(TargetPath)"/>

The more recommended way is writing your own .tasks and .targets files, and put all your references in it.
The naming standard for such files is [companyName].targets/tasks.

You can download the source code and the .tasks and .target files from here and start work with them.

0 Comments:

Post a Comment

<< Home