Product: | Syniti Data Replication, DBMoto |
Version: | Syniti DR 9.6 and above, DBMoto 9.5.1 and above |
ID: | 3012 |
Summary: | How to load .NET Core libraries into a script |
NET Core and .NET Framework are two different sets of libraries that are generally incompatible. Depending on the libraries used, a .NET FW application may need to be modified in order to be built in .NET Core. Both the .NET Core and .NET FW share the same code base library, namely .NET Standard. So essentially, .NET Standard is the framework compatible with both environments and if you write and compile code in .NET Standard, this code can be shared with both .NET Core and .NET Standard.
From this link: https://stackoverflow.com/questions/45872830/add-reference-to-a-net-core-2-0-dll-on-a-full-framework-4-7-project
-
It is possible to load a .NET Standard assembly from a .NET FW application. It is not possible to load a .NET Core assembly from a .NET FW application.
-
If you have a library built in .NET Core and would like to load it from a .NET FW application, you can try to recompile it in .NET Standard - or possibly build multiple platforms (.NET Core + .NET Standard) at once: https://docs.microsoft.com/en-us/visualstudio/ide/how-to-configure-projects-to-target-multiple-platforms?view=vs-2017
-
If you are unsure whether your code is fully compatible with .NET Standard, you can use this tool: https://marketplace.visualstudio.com/items?itemName=ConnieYau.NETPortabilityAnalyzer. The .NET Portability Analyzer will run through your code and will show (in percent) how compatible it is with .NET Standard, to help you measure how much effort is needed to make it compatible.
From Syniti DR/DBMoto, you can link a .NET Standard library to a script. Here is how to do it:
-
Build your library using .NET Standard 2.0 - let’s call it <mylibrary.dll>. Make sure to use the 2.0 version as this is the only version that is compatible with the .NET FW.
-
Copy your assembly <mylibrary.dll> into the Syniti DR/DBMoto installation folder
-
Open the script editor dialog and click the button to add references:
-
Add a reference to the netstandard assembly. In a standard path it can be found here: C:\Windows[Microsoft.NET|http://Microsoft.NET]\assembly\GAC_MSIL\netstandard\v4.0_2.0.0.0__cc7b13ffcd2ddd51\netstandard.dll
-
Add a reference to your .NET Standard library <mylibrary.dll>
-
Add a
using
reference in your script code specifying the namespace used in your library:using MyLibrary;
-
Write your own logic using the public methods and properties from your library.