Search code examples
c#dllreferencevisual-studio-2017fody-costura

How to prevent a referenced assembly's embedded dependency from being copied to output folder in Visual Studio?


I have:

  1. A.dll - a third-party assembly
  2. B.dll - my own class library assembly
  3. C.exe - my own executable

I am using the Costura.Fody NuGet package to embed A.dll into B.dll, and C.exe has a binary reference to B.dll.

(A.dll embedded within B.dll) <-- C.exe

When I build C.exe, however, A.dll appears in the output folder, despite already being embedded into B.dll (which is also copied to the output folder). I would prefer not to distribute what is essentially two copies of A.dll with my executable, but I would like to distribute A & B as one.

In B.dll, the "Copy Local" property of A.dll is set to false, and is instead explicitly included in Costura's FodyWeavers.xml.

Is there any way I can configure Costura.Fody and/or my reference properties so that A.dll is not copied independently into C.exe's output folder, while B.dll (with the embedded reference to A.dll) is copied?


Solution

  • After referring to msbuild trace log, I found that C.exe was resolving a path to A.dll in Program Files. Removing A.dll from Program Files solved my issue.