Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Native runtime packages compatible with .NET Framework (AnyCPU)? #4

Open
jngrb opened this issue Dec 17, 2021 · 3 comments
Open

Native runtime packages compatible with .NET Framework (AnyCPU)? #4

jngrb opened this issue Dec 17, 2021 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@jngrb
Copy link

jngrb commented Dec 17, 2021

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+ ?

@jngrb
Copy link
Author

jngrb commented Dec 20, 2021

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.

@jngrb jngrb changed the title Native runtime packages compatible with .NET Framework ? Native runtime packages compatible with .NET Framework (AnyCPU)? Dec 20, 2021
@Mizux Mizux self-assigned this Dec 20, 2021
@Mizux Mizux added the bug Something isn't working label Dec 21, 2021
@Mizux
Copy link
Owner

Mizux commented Jan 23, 2022

currently I use the code:

<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64</RuntimeIdentifiers>

and for the native library:
<OutputType>Library</OutputType>
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
<RuntimeIdentifier>@RUNTIME_IDENTIFIER@</RuntimeIdentifier>

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...

@Mizux
Copy link
Owner

Mizux commented Aug 26, 2022

did you try to update this line ?

<PackagePath>runtimes/@RUNTIME_IDENTIFIER@/native/%(Filename)%(Extension)</PackagePath>

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants