Custom MSBuild task with dependencies

msbuild

I have written an MSBuild task that makes use of third-party assemblies.

When I use the task in my project, MSBuild complains that it can't load the third-party assemblies (not surprisingly).

Where should I place the third-party assemblies so that they are available to MSBuild. I tried adding project references to them without success.

Best Answer

I'm not sure if I expressed my problem very well, but now I've found the solution.

In my .proj file, I reference my custom task with the following syntax...

<UsingTask AssemblyFile="..\lib\MyCompany.MSBuild\MyCompany.MSBuild.dll" TaskName="CreateDatabase" />

My CreateDatabase task relies on various 3rd-party assemblies. However, some of these are only referenced via reflection, so weren't included by default in the folder "..\lib\MyCompany.MSBuild".

I had been trying to get the task to work by placing the required assemblies in the same directory as the .proj file invoking the task.

However, what I should have been doing was putting the assemblies in the referenced task directory "..\lib\MyCompany.MSBuild\".

Simple!