MSBuild UsingTask Resolve References

It seems to me that I fixed it earlier, but I do not remember how.

I have a task file that looks like this (CustomTasks.tasks):

<UsingTask AssemblyFile="CustomTasks.dll" TaskName="MyCustomTask"/> 

it refers to the assembly (namely Ionic.Zip.dll). Ionic.Zip.dll is not located in the GAC (and I do not want it to be). It is located next to my CustomTasks.dll.

I have a directory called MSBuild one level from my sln file, which has CustomTasks.tasks, CustomTasks.dll and Ionic.Zip.dll.

I have csproj that references a task file and calls a custom task:

 <Import Project="$(ProjectDir)\..\MSBuild\CustomTasks.tasks" /> <MyCustomTask ..... /> 

during assembly, this gives:

The task "MyCustomTask" cannot be loaded from the assembly ... MyCustomTasks.dll. Failed to load file or assembly "Ionic.Zip, ......" or one of its dependencies.

+19
msbuild msbuild-task
Nov 25 '12 at 6:30
source share
2 answers

Tired and disappointed and took a direct approach ... I do not think that it is the same that I solved the problem earlier ... but perhaps this will help someone else. Other, more elegant solutions are more than welcome.

  <Target Name="BeforeBeforeBuild" BeforeTargets="BeforeBuild"> <HandleAssemblyResolve SearchPath="$(ProjectDir)\..\MSBuild\" /> </Target> <UsingTask TaskName="HandleAssemblyResolve" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> <ParameterGroup> <SearchPath ParameterType="System.String" Required="true" /> </ParameterGroup> <Task> <Using Namespace="System" /> <Using Namespace="System.IO" /> <Using Namespace="System.Reflection" /> <Code Type="Fragment" Language="cs"> <![CDATA[ AppDomain.CurrentDomain.AssemblyResolve += (sender, e) => { var assemblySearchPath = Path.Combine(SearchPath, e.Name.Split(',')[0]); if (File.Exists(assemblySearchPath)) return Assembly.LoadFrom(assemblySearchPath); return null; }; ]]> </Code> </Task> </UsingTask> 
+24
Nov 25
source share

This is really easy to fix. Put your own build tasks and dependencies in a different folder. Then the dependencies load correctly.

For example, like this:

 <UsingTask AssemblyFile="..\BuildTools\CustomTasks.dll" TaskName="MyCustomTask"/> 
0
Mar 16 '15 at 13:02
source share



All Articles