7

I have installed costura.fody into my project using nuget package. I have updated the FodyWeavers.xml file with:

<Costura 
Unmanaged32Assemblies='dllname'
Unmanaged64Assemblies='dllname' />

when I rebuild it and try to run the exe on seperate PC without the dll it doesnt work. Am I missing something ? Do I need to add anything else. I have also tried the following :

<IncludeAssemblies>
    dllname
</IncludeAssemblies>

Thank you for the help in advance.

Adds
  • 601
  • 2
  • 12
  • 24
  • What error message(s) are you getting? How do you know it's not working? – ashes999 Nov 13 '15 at 15:12
  • why not look in the `references` and see if the .dll is there.. remove the .dll then re-add it by browsing to the packages folder to locate the specific .dll. – MethodMan Nov 13 '15 at 15:14
  • When I rebuild the application the output build shows Costura/Fody : No Assemblies were embedded. @MethodMan There are no dlls in the references, can you please show me how to add to the packages folder. I am new to this so have no idea. when I try to add the dll as reference it gives error saying "file couldnt be added, please make sure file is accesssible or valid assemble or COM component" – Adds Nov 13 '15 at 15:21
  • I can't show you that.. if you are using `NuGet` you should navigate to the folder where your project is and look for a packages folder – MethodMan Nov 13 '15 at 15:23
  • @MethodMan I am new to this so have no idea. when I try to add the dll as reference it gives error saying "file couldnt be added, please make sure file is accesssible or valid assemble or COM component" – Adds Nov 13 '15 at 15:27
  • if it's a Nuget package.. then you should be able to add it..where on your local drive does the dll reside..? Create a folder in your project called Dependencies, then manually copy the dll there.. then in the project click add exiting item.. select that .dll once it shows up in the dependencies folder, then right click on reference-> add new reference, navigate to the Dependencies folder, select that .dll.. and make sure also that you have the .dll in your using statement at the top of the .cs file.. can you edit your question and paste in the using section so we can see – MethodMan Nov 13 '15 at 15:33
  • @MethodMan I tried what you suggested, but when I try to add reference from the dependency folder it gives the same error as above. any more suggestions ? How do I paste it to the using section ?? – Adds Nov 13 '15 at 15:54
  • do you have a .cs file where your code is ..? or is this an entry into the .config file..? – MethodMan Nov 13 '15 at 16:02
  • Yes I do have a .cs file, its Form1.cs , and I am using DllImport to import the dll as it is unmanaged code. – Adds Nov 13 '15 at 16:05

4 Answers4

17

I wanted to add an element to this that is important for unmanaged dll's when they aren't formally part of the solution/project.

@Adds is right to use:

<Costura 
Unmanaged32Assemblies='dllname'
Unmanaged64Assemblies='dllname' />

and @kdiddymcnasty is right to be careful about double-inclusion (but note that the IncludeAssemblies attribute is different from the Unmanaged##Assemblies attribute).

However, there's an additional piece to this, which is shown at this page. Essentially, you need to create a pair of folders in the project, called Costura32 and Costura64 and put the appropriate version of the dll in there, and set them to 'Embedded resource'. Then the weaver can include them in the exe when building the solution.

In my case, I was using the LibGit2Sharp dll, which relies on git2-15e1193.dll, so I have this as part of my solution:

project contents

and for each of those dll's, I have the Build Action set to Embedded Resource:

dll properties

Finally, the FodyWeavers.xml is:

<?xml version="1.0" encoding="utf-8" ?>
<Weavers>
  <costura IncludeDebugSymbls='false'>
    <Unmanaged32Assemblies>
      git2-15e1193
    </Unmanaged32Assemblies>
    <Unmanaged64Assemblies>
      git2-15e1193
    </Unmanaged64Assemblies>
  </costura>
</Weavers>

Make sure to leave the .dll off the dll names in the FodyWeavers.xml file.

Keith
  • 777
  • 8
  • 27
  • 2
    Thank you for this answer. This is also the answer to [this question](https://stackoverflow.com/questions/47079595/costura-fody-for-a-dll-that-references-another-dll). It would be great if you update that question so more people can benefit from this. – GY_ Apr 02 '18 at 15:29
  • 1
    Nice! Following all this steps I was able to include the missing assemblies, and now it's working. Thanks!! – Samuel Finatto Nov 04 '20 at 15:28
4

Make sure "Copy Local" is set to "True" within the reference properties tab on your desired libraries. Costura will not embed anything that does not have this setting enabled.

AnthonyOSX
  • 342
  • 5
  • 15
3

I was pulling my hair out with this issue and I couldn't find a solid answer. Eventually, I thought to look at the build output and noticed that it was embedding one of my dlls twice.

I had "Copy Local" set to "True" on that dll, and also included it in the FodyWeavers.xml, as @Adds did with "IncludeAssemblies" and "Unmanaged64Assemblies". When I set "Copy Local" to "False", the build output showed that it only embedded the dll once. When I ran the exe on a different PC, it worked fine.

0

Had a very similar issue.

For those who had Costura Fody installed, removed it and then reinstalled it only for it not to include the .dlls anymore. Go to your "packages" folder next to your .sln and remove it from there, remove the nuget and reinstall it again this fixed that issue :)

James
  • 27
  • 4