Gurobi 11.0 nuget package and netstandard 2.0
AnsweredOur use case is: We develop F# libraries (netstandard2.0 and MSIL) wrapping Gurobi. The resulting libraries are handed over the operations side, but also tested interactively with fsi (F# interpreter).
In particular, our dependency chain looks like: Gurobi nuget package => F# project 1 => ... => F# project n.
Since Gurobi 10 there is an official nuget package: How do I use Gurobi with NuGet? – Gurobi Help Center. We wanted to use it instead of vendoring the relevant dlls by hand.
When integrating Gurobi via a NuGet PackageReference
<PackageReference Include="Gurobi.Optimizer" Version="11.0.0" />
into a project with
<TargetFrameworks>netstandard2.0</TargetFrameworks>
only the gurobi110.netstandard20.dll
gets copied
to the output directory. When executing the code this results in the following error:
System.DllNotFoundException: Unable to load DLL 'gurobi110' or one of its dependencies: The
The error message is correct because the gurobi110.dll
is not present in the output directory.
The dll is only copied to the output directory by this PreBuildEvent inside the Gurobi nuget package, which only copies the dll
when the TargetFramework is e.g. net48
but not when it's netstandard2.0
.
<Target Name="Windows Build" AfterTargets="PreBuildEvent" Condition="($(TargetFramework.TrimEnd('0123456789')) == 'net' OR $(TargetFramework) == '') AND $([MSBuild]::IsOSPlatform('Windows'))"> <Copy DestinationFolder="$(OutputPath)" SourceFiles="$(MSBuildThisFileDirectory)..\runtimes\win-x64\native\gurobi100.dll" /> </Target>
This blocks our usage of the Gurobi nuget package. How can we include gurobi110.dll
in the build folders of all our projects 1 to n?
-
This was handled in a ticket.
0 -
Just to make some of the non-private ticket information public:
1) Adding the missing information to the nuget package (i.e., for `netstandard`) solves this problem only with the first project. Projects 2 to n do not get a copy of the Gurobi libraries. This seems to be an old MSBuild based build-chain limitation. See https://stackoverflow.com/questions/856278/why-the-native-dll-is-not-copied-to-the-output-directory.
1a) You can work around this by a direct reference to the Gurobi nuget package.
1a) Or do a custom post-build action.
1c) You can add a <RuntimeIdentifiers>...</RuntimeIdentifiers> in each downstream project.
* This builds with a single RID.
* With multiple RIDs this needs a build flag to choose a RID.
* This looses "full" netstandard, but works as the interactive use case has an intelligent user in front of the screen ... and we know where we currently run.
1d) You can switch to exe instead of Library for your project type. Loosing netstandard.0
Please sign in to leave a comment.
Comments
2 comments