I am using Rhino3dm nuget package (.net framework) inside my VSTO plugin for Excel. My aim is to generate .3dm file from excel and with data inside excel. I have done all the work on my developer machine. Everything is ok except one thing.
When project is build (using Visual studio), all references are copied to the output folder. Inside the output folder are a folders called Win32 and Win64 with “librhino3dm_native.dll” file.
When I run VSTO plugin on my machine from the Visual studio and run routine using Rhino3dm library it fails as “librhino3dm_native.dll” cannot be found. When this file is copied to the folder where “Rhino3dm.dll” is located it starts to work (again when run withing visual studio).
If I deploy and install VSTO plugin to target computer (not developers machine), problem with “librhino3dm_native.dll” persist. Somehow, when VSTO manifest is build it does not contain reference to “librhino3dm_native.dll”. So “Rhino3dm.dll” cannot see “librhino3dm_native.dll” as reference and fails.
I have tried to load “librhino3dm_native.dll” manually inside the routine but without a success.
I am not sure if it is solution to the issue, but is there a way to make “librhino3dm_native.dll” output to the same folder as other VSTO plugins. Or is there any other way how to overcome this issue?
I think problem is how librhino3dm_native.dll reference is handled when you build VSTO plugin (plugin for MS Office). When project is build, it is build to additional folder (one level deep in the reference folder). Thus plugin somehow ignores that reference.
I can share a project with you. However, it is not a public repo so I need email with which I can share.
@fraguada I have the same issue testing for.Net48
This is the solution after a bit of researches. Do you agree with this?
I think some of the updates in Visual Code also were related to the MSBuild.
<!--
Fix for DllNotFoundException: 'librhino3dm_native' in .NET Framework 4.8
Issue: .NET Framework's MSBuild doesn't automatically resolve the correct platform-specific
native libraries from NuGet packages like modern .NET does. Even though both win-x86 and
win-x64 versions exist in the Rhino3dm package, .NET Framework was copying the wrong
architecture or failing to copy any Windows native library to the output folder.
Solution: Explicitly specify the RuntimeIdentifier for .NET Framework 4.8 to ensure
MSBuild copies the correct win-x64 native library (librhino3dm_native.dll) to the
output directory. .NET 8.0 doesn't need this as it has superior cross-platform native
library resolution that automatically finds the correct library at runtime.
This only affects .NET Framework - modern .NET (8.0+) handles platform-specific
native library loading automatically without requiring explicit RID specification.
-->
<PropertyGroup Condition="'$(TargetFramework)' == 'net48'">
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>