- Notifications
You must be signed in to change notification settings - Fork2
C# NetStandard Library template that requires a C++ native library. Other C# libraries can use it as library reference or nuget reference with the same behavior.
License
Jorgemagic/NetStandard_And_NativeLibraries
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
C# NetStandard Library template that requires a C++ native library. Other C# libraries can use it as library reference or nuget reference with the same behavior.
- Visual Studio 2017. C# IDE on Windows.
- Visual Studio for Mac C# IDE on MacOS.
- Monodevelop C# IDE on Linux.
- CMake. C++ cross-compile tool.
Create a C# NetStandard library that requires a C++ Native Library. It must copy the correct native library file by platform(Windows, Linux and Mac) and architecture(x86 or x64) when it is referenced by another C# library/exe. Furthermore, the C# NetStandard library must be prepared to provide a nuget package. So you can use it as reference library(development) or nuget library(release) and the behavior must be the same.
- NativeLib folder is a simple C++ library that export aSum method.
- NativeLibWrapper folder with a C# netstandard wrapper(pinvoke).
- ConsoleApp_x86 x86 test that references NativeLibWrapper library.
- ConsoleApp_x64 x64 test that references NativeLibWrapper library.
- Nuget_x86 x86 test that references NativeLibWrapper nuget.
- Nuget_x64 x64 test that references NativeLibWrapper nuget.
Simple C++ library that export aSum function. This function receives two numbers and returns the sum of these numbers.
(in NativeLib folder)
mkdir Build_x86mkdir Build_x64cd Build_86cmake ../cmake --build .cd ..cd Build_64cmake -A x64 ../cmake --build .
- Select correct native library platform(Windows, Linux or Mac) and architecture(x86 or x64).
- Copy native library file to final project.
- Provide a valid nuget package.
- binaries folder: Contains the native library compiled files to all platforms.
- NativeLibWrapper.targets: Target to copy correct native libraries to final project by platform.(Based on solution name).
- DllRegister.cs: Class that select the correct native library architecture(x86 or x64) in runtime(only on Windows).
- NativeLibWrapper.dll.config: DLLMap file that indicates to pinvoke methods how to select the correct native library file on mono platforms(only on Linux and Mac).
- NativeLibWrapper.cs: Class with pinvoke method to native library.
- OpenUsingNativeLib_Nuget.sln solution
- Right click the projectNativeLibWrapper and select thePack command to generate nupkg file(Visual Studio 2017)
- Add nupkg folder as a new local repository inTool -> Options -> Nuget Package Manager -> Package Sources.
To add Android, iOS and UWP platforms.