XbimGeometry icon indicating copy to clipboard operation
XbimGeometry copied to clipboard

EngineXX.dll not copied to output directory - do I HAVE TO install the package in all exe/test projects?

Open ManIkWeet opened this issue 2 years ago • 2 comments

Short summary describing the issue. (3-5 sentences) If I create a super simple solution scenario:

  • ClassLibrary project containing some code making use of Xbim.Geometry NuGet package
  • ConsoleApplication project containing a main method calling the code in the above project

And run the ConsoleApplication, it will crash because it can't find the EngineXX.dll

Assemblies and versions affected:

Whatever is the latest 5.x

Steps (or code) to reproduce the issue:

One single image is enough I think afbeelding

Expected behavior:

I expect the Engine32 or Engine64 dll files to be copied to the output of ConsoleApplication1

Actual behavior or exception details:

Dll file is not copied, causing runtime crash

Additional Details

Yes there are many existing issues for this, but none describe a solution that I

  1. understand
  2. am happy with

I have multiple output assemblies, all in their own bin folder (many test assemblies), and I don't want to add the large amount of NuGet packages to all of them if it can be avoided...

Is it possible to add something to the ClassLibrary project to make MSBUILD copy the EngineXX.dll files to any top level output directory?

ManIkWeet avatar Apr 20 '22 19:04 ManIkWeet

OK: so you understand. The reason for this is because Xbim.Geometry.EngineXX.dll is not a managed assembly, so the .net compiler doesn't automatically treat it as a transitive dependency and copy it to upstream output folders.

We've worked around this with a Nuget/msbuild extension (based I think, off the approach from System.Data.SqlLite which has a similar issue with the unmanaged SqlLite.Interop.dll). See https://github.com/xBimTeam/XbimGeometry/blob/master/Xbim.Geometry.Engine.Interop.targets

... which is content we add to the Nuget package to deploy the unmanaged assemblies during builds. But this doesn't work for Transitive dependencies. i.e. Xbim.Geometry.Engine -> YourLib -> YourExe

Workaround: Add a reference to Xbim.Geometry or Xbim.Geometry.Engine.Interop package to the entry project

Proper solution: it seems there is a mechanism to deploy a similar build script that also deploys transitive dependencies - this was introduced in Nuget 5.0. See how SqlLite does this:

image

PRs welcome for this!

andyward avatar Aug 16 '22 18:08 andyward

A different solution that I came up with, which actually works reasonably well for me, is to consolidate all my Ifc code usage to a single project, with the NuGet packages, and use Fody Costura to turn it into a single .dll - this supports native .dll embeds too.

ManIkWeet avatar Aug 16 '22 18:08 ManIkWeet