Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom MSBuild task with dependencies

Tags:

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.

like image 460
sandy Avatar asked Oct 28 '09 10:10

sandy


2 Answers

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!

like image 60
sandy Avatar answered Nov 08 '22 16:11

sandy


You could add them to the GAC (Global Assemby Cache). This only works if it is strongly named.

You could also make sure that you have marked them with copy local = true when you added the reference in the project.

like image 1
Shiraz Bhaiji Avatar answered Nov 08 '22 17:11

Shiraz Bhaiji