How to solve: Custom MSBuild task requires assembly outside of AppBase
Asked Answered
E

4

6

I have a custom Task that I want to execute when building my C# projects. This task is located in MyTask.dll, which references another assembly, MyCommon.DLL.

The problem is that MyCommon.dll is located at "..\Common\MyCommon.dll" relative to MyTask.dll, which puts it outside the AppBase dir for MSBuild process. I've confirmed that this is indeed the problem by analyzing MSBuild's log and seeing Fusion's report about the binding failure.

What can I do to make Fusion find MyCommon.dll during the build process? Note that moving the assembly would break my app, which also depends on it.

UPDATE: Well, it seems I'll go with using a copy afterall. Other solutions all require system-wide modifications, which isn't really warranted here.

Enlist answered 27/3, 2009 at 16:21 Comment(0)
W
2

So copy it instead? Just a thought. Have a copy there just to support the build that you delete once you're done with it.

Wichman answered 27/3, 2009 at 16:23 Comment(2)
Yeah, I'm saving that to use as the very last resort. It feels clunky and I hope there's a better way. :)Enlist
Agreed. But none I can think of sadly. We'll see what the rest of them come up with.Wichman
R
1

I see multiple solutions :

1st : Add the assembly in the GAC (your assembly must have a strong name)

gacutil /I <assembly name> 

2nd : Locate the assembly through Codebases or Probing, in your machine.config file or in msbuild.exe.config .

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="MyCommon"
                              publicKeyToken="32ab4ba45e0a69a1"
                              culture="neutral" />
            <codeBase version="2.0.0.0"
                      href="file://C:/yourpath/MyCommon.DLL"/>
         </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

3rd : copy the assembly in the same directory before and delete it after, like David M said.

Remonaremonetize answered 27/3, 2009 at 16:52 Comment(0)
S
0

All of these "solutions" create more dependencies which complicate the environment. There should be an easier way to update the probing path at runtime..

Specifically MSBuild should allow you to add probing paths in your .proj file, or to specify the dependant dlls

You can define a custom UsingTask:

<UsingTask TaskName="Task" AssemblyFile="Assembly.dll" />

but you cant add dependencies? it should be included... here with something like

<UsingTask TaskName="Task" AssemblyFile="Assembly.dll">
<DependantAssembly AssemblyFile="dependant.dll"/>
</UsingTask>

But, no this isn't supported...

Slang answered 20/7, 2009 at 20:54 Comment(0)
B
0

An option is to use ILMerge to merge the dependency into the task assembly.

Butterfly answered 11/9, 2012 at 5:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.