dotnet-native
dotnet-native copied to clipboard
Native runtime packages compatible with .NET Framework (AnyCPU)?
How can I produce runtime packages compatible with .NET Framework?
I tried to change the framework identified netcoreapp3.1 to netstandard2.0 or net461 but I failed to produce working examples.
The reason why I fail to run the examples is that there are no native DLLs copied to the binary space for the example project:
Analysis of the differences:
- Working with netcoreapp3.1: The folder
\dotnet\examples\Example\bin\Debug\netcoreapp3.1 contains a subfolder runtimes\win-x64\native with the native DLLs. -
Not Working with standard2.0: The folder
\dotnet\examples\Example\bin\Debug\netstandard2.0 contains no native DLLS and neither a subfolder runtimes subfolder
The nuspec files for the wrapper and native package are the same except for the targetFramework identifier.
Are runtime packages restricted to .NET core and .NET 5.0+ ?
After a lot of investigation, I found the problem: using platform "AnyCPU" will not copy any native DLL to the target directory. So I need to add <Platforms>x86;x64</Platforms>
to all tests and example projects to make it work.
With a specific platform, the native DLL will be copied to \dotnet\examples\Example\bin<platform>\Debug\net461 (or any other .NET Framework identified) - straight, not in a runtimes subfolder. Then it will work to load it during runtime.
I will leave this issue open because I will investigate a bit whether a "AnyCPU" solution can be found. If I do so, I will post it here.
currently I use the code: https://github.com/Mizux/dotnet-native/blob/09f088b3ccabf9e1316db9c28b5042f0f2a2ab10/dotnet/Mizux.DotnetNative.csproj.in#L4-L5 and for the native library: https://github.com/Mizux/dotnet-native/blob/2b2c3b74775a371d3765687525f4edc10eacb5a4/dotnet/Mizux.DotnetNative.runtime.csproj.in#L3-L5
You should change theses TFM also IMHO. todo: test to write an example in another TFM to see what happen
also don't hesitate to clean your local cache
dotnet nuget locals all --clear
otherwise you may test with your previous package...
did you try to update this line ?
https://github.com/Mizux/dotnet-native/blob/97eb1a3485ad219ca776759e1613cdbb3bb6c78a/dotnet/Mizux.DotnetNative.runtime.csproj.in#L33
AFAIK TFM netcoreapp3.1
and net6.0
will look into native/
dir to load native library so we put them here, you need to reverse native library auto loading in net461 etc...
You may take a look at https://github.com/google/or-tools/blob/8d19323faf51f2f004e4de6c1b32a74001fbc7c1/ortools/dotnet/Google.OrTools.runtime.win-x64/Google.OrTools.runtime.win-x64.csproj.in#L33-L38 https://github.com/google/or-tools/blob/v8.0/ortools/dotnet/Google.OrTools.runtime.win-x64/Google.OrTools.runtime.win-x64.targets