diff --git a/.github/workflows/build-publish.yml b/.github/workflows/release-all.yml similarity index 52% rename from .github/workflows/build-publish.yml rename to .github/workflows/release-all.yml index afb08107..c0cc86d0 100644 --- a/.github/workflows/build-publish.yml +++ b/.github/workflows/release-all.yml @@ -1,11 +1,11 @@ -name: Build and publish libplctag.NET nuget package +name: Release all on: [workflow_dispatch] jobs: build: - runs-on: ubuntu-latest + runs-on: windows-latest steps: - uses: actions/checkout@v4 @@ -13,4 +13,4 @@ jobs: lfs: true - name: Publish all packages on version change - run: ./build.sh ReleaseAll --nuget-api-key ${{secrets.NUGET_API_KEY}} + run: .\build.cmd ReleaseAll --nuget-api-key ${{secrets.NUGET_API_KEY}} diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/test-libplctag.yml similarity index 75% rename from .github/workflows/continuous_integration.yml rename to .github/workflows/test-libplctag.yml index 8bdadca0..844c06c2 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/test-libplctag.yml @@ -1,4 +1,4 @@ -name: CI - Run all tests +name: Test libplctag on: [push] @@ -13,4 +13,4 @@ jobs: lfs: true - name: Build all and run tests - run: ./build.sh Test + run: ./build.sh TestLibplctag diff --git a/.github/workflows/test-libplctagNativeImport.yml b/.github/workflows/test-libplctagNativeImport.yml new file mode 100644 index 00000000..bae28121 --- /dev/null +++ b/.github/workflows/test-libplctagNativeImport.yml @@ -0,0 +1,16 @@ +name: Test libplctag.NativeImport + +on: [workflow_dispatch,push] + +jobs: + build: + + runs-on: windows-latest + + steps: + - uses: actions/checkout@v4 + with: + lfs: true + + - name: Build all and run tests + run: .\build.cmd TestLibplctagNativeImport diff --git a/.github/workflows/update_libplctag_core.yml b/.github/workflows/update-core-binaries.yml similarity index 95% rename from .github/workflows/update_libplctag_core.yml rename to .github/workflows/update-core-binaries.yml index a2c81616..a8f6c912 100644 --- a/.github/workflows/update_libplctag_core.yml +++ b/.github/workflows/update-core-binaries.yml @@ -1,4 +1,4 @@ -name: Update libplctag core +name: Update core binaries on: diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index 9f2fad64..c2bce521 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -86,10 +86,8 @@ "PackLibplctag", "PackLibplctagNativeImport", "ReleaseAll", - "ReleaseLibplctag", - "ReleaseLibplctagNativeImport", - "Restore", - "Test", + "TestLibplctag", + "TestLibplctagNativeImport", "UpdateCoreBinaries" ] } @@ -109,10 +107,8 @@ "PackLibplctag", "PackLibplctagNativeImport", "ReleaseAll", - "ReleaseLibplctag", - "ReleaseLibplctagNativeImport", - "Restore", - "Test", + "TestLibplctag", + "TestLibplctagNativeImport", "UpdateCoreBinaries" ] } diff --git a/DEVELOPERS.md b/DEVELOPERS.md index 9073c477..0964dc44 100644 --- a/DEVELOPERS.md +++ b/DEVELOPERS.md @@ -27,13 +27,22 @@ GitHub Actions have been created to automate some common activities such as upda These workflows delegate the actual automation logic to the [`_build`](../build) [NUKE](https://nuke.build/) project. -### How to release Nuget packages +## Testing libplctag.NativeImport + +libplctag.NativeImport uses features of Nuget and MSBuild to distribute the libplctag core binaries. +What actually needs to be tested is that logic, which xUnit and other unit-testing frameworks are not well equipped to do. +The build project, however, is capable - and does this by creating orchestrating a package creation, and using it in the restore process for those test suites. + +Different versions of .NET use packages differently (see [PackageReference vs packags.config](https://learn.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference)), so there are different test projects for each variation. + + +## How to release Nuget packages 1. Update the version number in the csproj files of the libplctag or libplctag.NativeImport projects. 2. Trigger the "Build and publish libplctag.NET nuget package" workflow. 4. Create a GitHub "Release" with details of the new release. -## How to update the core binaries libplctag.NativeImport +## How to update the libplctag core binaries When a new version of libplctag core is released, the library binaries need to be updated in libplctag.NativeImport. The build script can be used to copy these libraries in the project without error. @@ -41,4 +50,5 @@ The build script can be used to copy these libraries in the project without erro 1. Trigger the "Update libplctag core" workflow. 2. Verify that the files have been correctly copied. 3. Make relevant modifications to libplctag.NativeImport such as modifying the method signatures (if required). -4. Finally, release the updated project as a new Nuget packages. +4. Release the updated project as a new Nuget package. +5. Finally, update the libplctag.NativeImport `` version in the libplctag package, and release that. diff --git a/build/Build.cs b/build/Build.cs index c946844c..f8172342 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -8,6 +8,8 @@ using Nuke.Common.ProjectModel; using Nuke.Common.Tools.DotNet; using Nuke.Common.Tools.GitVersion; +using Nuke.Common.Tools.NuGet; +using Nuke.Common.Tools.VSTest; using Nuke.Common.Utilities.Collections; using Serilog; using static Nuke.Common.IO.FileSystemTasks; @@ -17,7 +19,7 @@ class Build : NukeBuild { - public static int Main() => Execute(x => x.Test); + public static int Main() => Execute(x => x.TestLibplctag); [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; @@ -29,51 +31,137 @@ class Build : NukeBuild AbsolutePath SourceDirectory => RootDirectory / "src"; AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts"; + AbsolutePath PackageRestoreDirectory => SourceDirectory / "packages"; Project libplctag => Solution.GetProject("libplctag"); Project libplctag_NativeImport => Solution.GetProject("libplctag.NativeImport"); Target Clean => _ => _ - .Before(Restore) .Executes(() => { - DotNetClean(); - SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(dir => dir.DeleteDirectory()); - ArtifactsDirectory.CreateOrCleanDirectory(); - }); - - Target Restore => _ => _ - .Executes(() => - { - DotNetRestore(s => s - .SetProjectFile(Solution)); + SourceDirectory.GlobDirectories("**/bin", "**/obj") + .Concat(ArtifactsDirectory) + .Concat(PackageRestoreDirectory) + .ForEach(dir => + { + Log.Debug("Deleting {0}", dir); + dir.DeleteDirectory(); + }); }); Target Compile => _ => _ - .DependsOn(Restore) + .DependsOn(Clean) .Executes(() => { DotNetBuild(s => s - .SetProjectFile(Solution) + .SetProjectFile(libplctag) + .SetConfiguration(Configuration) + ); + + DotNetBuild(s => s + .SetProjectFile(libplctag_NativeImport) .SetConfiguration(Configuration) - .EnableNoRestore() ); }); - Target Test => _ => _ + Target TestLibplctag => _ => _ .DependsOn(Compile) .Executes(() => { DotNetTest(s => s - .SetProjectFile(Solution) - .SetConfiguration(Configuration) - .EnableNoRestore() - ); + .SetProjectFile(libplctag) + .SetConfiguration(Configuration) + ); + }); + + + Target TestLibplctagNativeImport => _ => _ + .DependsOn(PackLibplctagNativeImport) + .DependsOn(PackLibplctag) + .Executes(() => + { + var testsNetCore = Solution.GetAllProjects("libplctag.NativeImport.Tests.NetCore.*"); + var testsNetFramework = Solution.GetAllProjects("libplctag.NativeImport.Tests.NetFramework.*"); + + // This nuget.config file ensures that libplctag and libplctag.NativeImport are restored from the + // newly created and packed packages on disk, but still allows all other packages to be + // downloaded from the remote nuget feed. + var nuget_config_contents = $""" + + + + + + + + + + + + + + + + + + + + + + + + + +"""; + + var nuget_config = Path.GetTempFileName() + ".nuget.config"; + File.WriteAllText(nuget_config, nuget_config_contents); + + foreach (var proj in testsNetFramework) + { + var outDir = proj.GetMSBuildProject(Configuration).GetPropertyValue("OutputPath"); + var assembly = proj.Directory / outDir / proj.Name + ".dll"; + + NuGetTasks.NuGetRestore(s => s + .SetTargetPath(proj) + .SetPackagesDirectory(PackageRestoreDirectory) + .SetConfigFile(nuget_config) + ); + + DotNetMSBuild(s => s + .SetTargetPath(proj) + .SetConfiguration(Configuration) + .SetBinaryLog(assembly + ".binlog") // VIew with https://msbuildlog.com/ + ); + + VSTestTasks.VSTest(assembly.ToString()); + } + + foreach (var proj in testsNetCore) + { + DotNetRestore(s => s + .SetProjectFile(proj) + .SetPackageDirectory(PackageRestoreDirectory) + .SetConfigFile(nuget_config) + ); + + DotNetBuild(s => s + .SetProjectFile(proj) + .SetConfiguration(Configuration) + .SetNoRestore(true) + ); + + DotNetTest(s => s + .SetProjectFile(proj) + .SetNoRestore(true) + ); + } + + File.Delete(nuget_config); }); Target PackLibplctag => _ => _ - .DependsOn(Test) .Executes(() => { DotNetPack(s => s @@ -83,11 +171,10 @@ class Build : NukeBuild .EnableNoRestore() .SetOutputDirectory(ArtifactsDirectory) ); - }); Target PackLibplctagNativeImport => _ => _ - .DependsOn(Test) + .DependsOn(Compile) .Executes(() => { DotNetPack(s => s @@ -100,31 +187,9 @@ class Build : NukeBuild }); - Target ReleaseLibplctag => _ => _ - .DependsOn(PackLibplctag) - .Requires(() => NugetApiUrl) - .Requires(() => NugetApiKey) - .Requires(() => Configuration.Equals(Configuration.Release)) - .Executes(() => - { - var version = libplctag.GetProperty("Version"); - PushAndTag($"libplctag.{version}.nupkg", $"libplctag-v{version}"); - }); - - Target ReleaseLibplctagNativeImport => _ => _ - .DependsOn(PackLibplctagNativeImport) - .Requires(() => NugetApiUrl) - .Requires(() => NugetApiKey) - .Requires(() => Configuration.Equals(Configuration.Release)) - .Executes(() => - { - var version = libplctag_NativeImport.GetProperty("Version"); - PushAndTag($"libplctag.NativeImport.{version}.nupkg", $"libplctag.NativeImport-v{version}"); - }); - Target ReleaseAll => _ => _ - .DependsOn(PackLibplctag) - .DependsOn(PackLibplctagNativeImport) + .DependsOn(TestLibplctag) + .DependsOn(TestLibplctagNativeImport) .Requires(() => NugetApiUrl) .Requires(() => NugetApiKey) .Requires(() => Configuration.Equals(Configuration.Release)) @@ -142,20 +207,20 @@ class Build : NukeBuild .Executes(() => { - var runtimesFolder = RootDirectory / "src" / "libplctag.NativeImport" / "runtime"; + var runtimesFolder = RootDirectory / "src" / "libplctag.NativeImport" / "runtimes"; (string zipFileName, string[] unzipPath, AbsolutePath destination)[] releases = { - ($"libplctag_{LibplctagCoreVersion}_macos_x64.zip", ["libplctag.dylib"], runtimesFolder/"osx_x64"/"libplctag.dylib" ), - ($"libplctag_{LibplctagCoreVersion}_macos_aarch64.zip", ["libplctag.dylib"], runtimesFolder/"osx_ARM64"/"libplctag.dylib" ), - ($"libplctag_{LibplctagCoreVersion}_ubuntu_x64.zip", ["libplctag.so"], runtimesFolder/"linux_x64"/"libplctag.so" ), - ($"libplctag_{LibplctagCoreVersion}_ubuntu_x86.zip", ["libplctag.so"], runtimesFolder/"linux_x86"/"libplctag.so" ), - ($"libplctag_{LibplctagCoreVersion}_linux_arm7l.zip", ["libplctag.so"], runtimesFolder/"linux_ARM"/"libplctag.so" ), - ($"libplctag_{LibplctagCoreVersion}_linux_aarch64.zip", ["libplctag.so"], runtimesFolder/"linux_ARM64"/"libplctag.so" ), - ($"libplctag_{LibplctagCoreVersion}_windows_x64.zip", ["Release", "plctag.dll"], runtimesFolder/"win_x64"/"plctag.dll" ), - ($"libplctag_{LibplctagCoreVersion}_windows_x86.zip", ["Release", "plctag.dll"], runtimesFolder/"win_x86"/"plctag.dll" ), - ($"libplctag_{LibplctagCoreVersion}_windows_Arm.zip", ["Release", "plctag.dll"], runtimesFolder/"win_ARM"/"plctag.dll" ), - ($"libplctag_{LibplctagCoreVersion}_windows_Arm64.zip", ["Release", "plctag.dll"], runtimesFolder/"win_ARM64"/"plctag.dll" ), + ($"libplctag_{LibplctagCoreVersion}_macos_x64.zip", ["libplctag.dylib"], runtimesFolder/"osx-x64"/"native"/"libplctag.dylib" ), + ($"libplctag_{LibplctagCoreVersion}_macos_aarch64.zip", ["libplctag.dylib"], runtimesFolder/"osx-arm64"/"native"/"libplctag.dylib" ), + ($"libplctag_{LibplctagCoreVersion}_ubuntu_x64.zip", ["libplctag.so"], runtimesFolder/"linux-x64"/"native"/"libplctag.so" ), + ($"libplctag_{LibplctagCoreVersion}_ubuntu_x86.zip", ["libplctag.so"], runtimesFolder/"linux-x86"/"native"/"libplctag.so" ), + ($"libplctag_{LibplctagCoreVersion}_linux_arm7l.zip", ["libplctag.so"], runtimesFolder/"linux-arm"/"native"/"libplctag.so" ), + ($"libplctag_{LibplctagCoreVersion}_linux_aarch64.zip", ["libplctag.so"], runtimesFolder/"linux-arm64"/"native"/"libplctag.so" ), + ($"libplctag_{LibplctagCoreVersion}_windows_x64.zip", ["Release", "plctag.dll"], runtimesFolder/"win-x64"/"native"/"plctag.dll" ), + ($"libplctag_{LibplctagCoreVersion}_windows_x86.zip", ["Release", "plctag.dll"], runtimesFolder/"win-x86"/"native"/"plctag.dll" ), + ($"libplctag_{LibplctagCoreVersion}_windows_Arm.zip", ["Release", "plctag.dll"], runtimesFolder/"win-arm"/"native"/"plctag.dll" ), + ($"libplctag_{LibplctagCoreVersion}_windows_Arm64.zip", ["Release", "plctag.dll"], runtimesFolder/"win-arm64"/"native"/"plctag.dll" ), }; var downloadFolder = RootDirectory / "downloads"; @@ -197,7 +262,8 @@ private void PushAndTag(string packageFilename, string tag) .EnableSkipDuplicate() ); - if (output.Any(line => line.Text.Contains("Conflict", StringComparison.InvariantCultureIgnoreCase))) { + if (output.Any(line => line.Text.Contains("Conflict", StringComparison.InvariantCultureIgnoreCase))) + { Log.Information("{0} already exists in package repository", packageFilename); return; } diff --git a/build/_build.csproj b/build/_build.csproj index b1965fae..0e46b1cf 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -15,4 +15,9 @@ + + + + + diff --git a/docs/libplctag.NativeImport.md b/docs/libplctag.NativeImport.md index a761b999..56a04fb3 100644 --- a/docs/libplctag.NativeImport.md +++ b/docs/libplctag.NativeImport.md @@ -33,29 +33,6 @@ Further examples can be found [here](../examples/CSharp%20NativeImport/). ## How it works -During initialization, this package extracts to disk the appropriate (platform-specific) core library. -By default, it will overwrite files with the same filename (`plctag.dll`, `libplctag.so`, or `libplctag.dylib`). - -If you wish to disable this behaviour and use a different core library (e.g. one that you've compiled yourself, or a pre-release), you can disable the Force Extract feature. - -```csharp -// Before any calls to any libplctag methods -plctag.ForceExtractLibrary = false; -``` - The libplctag core library can be compiled for [many platforms](https://github.com/libplctag/libplctag#platform-support), and not all supported platforms are shipped with this wrapper. -If you get a `TypeLoadException`, chances are that you can still use this wrapper but you will need to [supply the runtime yourself](https://github.com/libplctag/libplctag/blob/master/BUILD.md). - -## Developing for systems with immutable application directories - -UWP, Xamarin.Forms and some other frameworks produce executables that, when installed, can not modify their own application directory. -[libplctag.NativeImport](https://www.nuget.org/packages/libplctag.NativeImport/) relies on the ability to extract the native library to this location, so on these platforms, libplctag will not work. - -The workaround is to supply the appropriate binary(ies) yourself: -1. Get the core library (e.g. plctag.dll) from [Releases](https://github.com/libplctag/libplctag/releases). -2. Add this file to your project such that it is copied to the output directory. -3. Set `plctag.ForceExtractLibrary = false` before any other calls to libplctag. - -Watch out for x64/x86 mismatches between the native library you downloaded and your solution. +If you get a `TypeLoadException`, chances are that you can still use this wrapper but you will need to [supply the core libplctag library yourself](https://github.com/libplctag/libplctag/blob/master/BUILD.md). -This bug is tracked in https://github.com/libplctag/libplctag.NET/issues/137 diff --git a/src/libplctag.NativeImport.Benchmarks/Program.cs b/src/libplctag.NativeImport.Benchmarks/Program.cs deleted file mode 100644 index 7a515205..00000000 --- a/src/libplctag.NativeImport.Benchmarks/Program.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) libplctag.NET contributors -// https://github.com/libplctag/libplctag.NET -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Running; -using System; - -namespace libplctag.NativeImport.Benchmarks -{ - [MemoryDiagnoser] - public class GetStatusRawVsExtractFirst - { - - public GetStatusRawVsExtractFirst() - { - // In order for this to compile you need to make this function public, it is normally a private method. - // And of course you need to reference the project rather than the package. - //LibraryExtractor.Init(); - throw new NotImplementedException(); - } - - [Benchmark] - public int Raw() - { - // In order for this to compile you need to make this function public, it is normally a private method. - // And of course you need to reference the project rather than the package. - //return plctag.plc_tag_check_lib_version_raw(0, 0, 0); - throw new NotImplementedException(); - } - - [Benchmark] - public int ExtractFirst() - { - return plctag.plc_tag_check_lib_version(0, 0, 0); - } - - } - - public class Program - { - public static void Main(string[] args) - { - var summary = BenchmarkRunner.Run(); - } - } -} diff --git a/src/libplctag.NativeImport.Benchmarks/libplctag.NativeImport.Benchmarks.csproj b/src/libplctag.NativeImport.Benchmarks/libplctag.NativeImport.Benchmarks.csproj deleted file mode 100644 index cedbda9d..00000000 --- a/src/libplctag.NativeImport.Benchmarks/libplctag.NativeImport.Benchmarks.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - Exe - net8.0 - - - - - - - - - - - diff --git a/src/libplctag.NativeImport.Tests.NetCore.DirectDependency/Test.cs b/src/libplctag.NativeImport.Tests.NetCore.DirectDependency/Test.cs new file mode 100644 index 00000000..2d100155 --- /dev/null +++ b/src/libplctag.NativeImport.Tests.NetCore.DirectDependency/Test.cs @@ -0,0 +1,22 @@ +// Copyright (c) libplctag.NET contributors +// https://github.com/libplctag/libplctag.NET +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace libplctag.NativeImport.Tests.NetCore.DirectDependency +{ + public class Test + { + [Fact] + public void Can_execute_native_methods() + { + // The test is succesful if this does not throw + var output = plctag.plc_tag_check_lib_version(0, 0, 0); + + // The below is redundant but is used to prove to the reader that the test works + Assert.True(true); + } + } +} diff --git a/src/libplctag.NativeImport.Tests.NetCore.DirectDependency/libplctag.NativeImport.Tests.NetCore.DirectDependency.csproj b/src/libplctag.NativeImport.Tests.NetCore.DirectDependency/libplctag.NativeImport.Tests.NetCore.DirectDependency.csproj new file mode 100644 index 00000000..f5234071 --- /dev/null +++ b/src/libplctag.NativeImport.Tests.NetCore.DirectDependency/libplctag.NativeImport.Tests.NetCore.DirectDependency.csproj @@ -0,0 +1,33 @@ + + + + net8.0 + enable + enable + + false + true + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + diff --git a/src/libplctag.NativeImport.Tests.NetCore.TransitiveDependency/Test.cs b/src/libplctag.NativeImport.Tests.NetCore.TransitiveDependency/Test.cs new file mode 100644 index 00000000..a0d9877b --- /dev/null +++ b/src/libplctag.NativeImport.Tests.NetCore.TransitiveDependency/Test.cs @@ -0,0 +1,22 @@ +// Copyright (c) libplctag.NET contributors +// https://github.com/libplctag/libplctag.NET +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +namespace libplctag.NativeImport.Tests.NetCore.TransitiveDependency +{ + public class Test + { + [Fact] + public void Can_execute_native_methods() + { + // The test is succesful if this does not throw + var output = LibPlcTag.IsRequiredVersion(0, 0, 0); + + // The below is redundant but is used to prove to the reader that the test works + Assert.True(true); + } + } +} \ No newline at end of file diff --git a/src/libplctag.NativeImport.Tests/libplctag.NativeImport.Tests.csproj b/src/libplctag.NativeImport.Tests.NetCore.TransitiveDependency/libplctag.NativeImport.Tests.NetCore.TransitiveDependency.csproj similarity index 62% rename from src/libplctag.NativeImport.Tests/libplctag.NativeImport.Tests.csproj rename to src/libplctag.NativeImport.Tests.NetCore.TransitiveDependency/libplctag.NativeImport.Tests.NetCore.TransitiveDependency.csproj index cd7f8af6..3b9af7fb 100644 --- a/src/libplctag.NativeImport.Tests/libplctag.NativeImport.Tests.csproj +++ b/src/libplctag.NativeImport.Tests.NetCore.TransitiveDependency/libplctag.NativeImport.Tests.NetCore.TransitiveDependency.csproj @@ -1,26 +1,30 @@ - + net8.0 + enable + enable false + true - - - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/libplctag.NativeImport.Tests.NetFramework.DirectDependency/Properties/AssemblyInfo.cs b/src/libplctag.NativeImport.Tests.NetFramework.DirectDependency/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..4905f441 --- /dev/null +++ b/src/libplctag.NativeImport.Tests.NetFramework.DirectDependency/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("libplctag.NativeImport.Tests.NetFramework")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("libplctag.NativeImport.Tests.NetFramework")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("b8584170-3d77-4a0f-bd89-56c49aff6069")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/libplctag.NativeImport.Tests.NetFramework.DirectDependency/Test.cs b/src/libplctag.NativeImport.Tests.NetFramework.DirectDependency/Test.cs new file mode 100644 index 00000000..66bbdc2f --- /dev/null +++ b/src/libplctag.NativeImport.Tests.NetFramework.DirectDependency/Test.cs @@ -0,0 +1,25 @@ +// Copyright (c) libplctag.NET contributors +// https://github.com/libplctag/libplctag.NET +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace libplctag.NativeImport.Tests.NetFramework.DirectDependency +{ + [TestClass] + public class Test + { + [TestMethod] + public void Can_execute_native_methods() + { + // The test is succesful if this does not throw + var output = plctag.plc_tag_check_lib_version(0, 0, 0); + + // The below is redundant but is used to prove to the reader that the test works + Assert.IsTrue(true); + } + } +} diff --git a/src/libplctag.NativeImport.Tests.NetFramework.DirectDependency/app.config b/src/libplctag.NativeImport.Tests.NetFramework.DirectDependency/app.config new file mode 100644 index 00000000..dfb9dea8 --- /dev/null +++ b/src/libplctag.NativeImport.Tests.NetFramework.DirectDependency/app.config @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/libplctag.NativeImport.Tests.NetFramework.DirectDependency/libplctag.NativeImport.Tests.NetFramework.DirectDependency.csproj b/src/libplctag.NativeImport.Tests.NetFramework.DirectDependency/libplctag.NativeImport.Tests.NetFramework.DirectDependency.csproj new file mode 100644 index 00000000..d1bf4e73 --- /dev/null +++ b/src/libplctag.NativeImport.Tests.NetFramework.DirectDependency/libplctag.NativeImport.Tests.NetFramework.DirectDependency.csproj @@ -0,0 +1,143 @@ + + + + + + + + + + Debug + AnyCPU + {B8584170-3D77-4A0F-BD89-56C49AFF6069} + Library + Properties + libplctag.NativeImport.Tests.NetFramework.DirectDependency + libplctag.NativeImport.Tests.NetFramework.DirectDependency + v4.7.2 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\libplctag.NativeImport.1.0.41\lib\net472\libplctag.NativeImport.dll + True + + + ..\packages\Microsoft.ApplicationInsights.2.22.0\lib\net46\Microsoft.ApplicationInsights.dll + + + + ..\packages\Microsoft.Testing.Extensions.Telemetry.1.2.1\lib\netstandard2.0\Microsoft.Testing.Extensions.Telemetry.dll + + + ..\packages\Microsoft.Testing.Extensions.TrxReport.Abstractions.1.2.1\lib\netstandard2.0\Microsoft.Testing.Extensions.TrxReport.Abstractions.dll + + + ..\packages\Microsoft.Testing.Extensions.VSTestBridge.1.2.1\lib\netstandard2.0\Microsoft.Testing.Extensions.VSTestBridge.dll + + + ..\packages\Microsoft.Testing.Platform.1.2.1\lib\netstandard2.0\Microsoft.Testing.Platform.dll + + + ..\packages\Microsoft.Testing.Platform.MSBuild.1.2.1\lib\netstandard2.0\Microsoft.Testing.Platform.MSBuild.dll + + + ..\packages\Microsoft.TestPlatform.ObjectModel.17.10.0\lib\net462\Microsoft.TestPlatform.CoreUtilities.dll + + + ..\packages\Microsoft.TestPlatform.ObjectModel.17.10.0\lib\net462\Microsoft.TestPlatform.PlatformAbstractions.dll + + + ..\packages\Microsoft.TestPlatform.ObjectModel.17.10.0\lib\net462\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll + + + ..\packages\MSTest.TestFramework.3.4.3\lib\net462\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.3.4.3\lib\net462\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + ..\packages\NuGet.Frameworks.6.10.1\lib\net472\NuGet.Frameworks.dll + + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + ..\packages\System.Collections.Immutable.8.0.0\lib\net462\System.Collections.Immutable.dll + + + + + ..\packages\System.Diagnostics.DiagnosticSource.8.0.1\lib\net462\System.Diagnostics.DiagnosticSource.dll + + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Reflection.Metadata.8.0.0\lib\net462\System.Reflection.Metadata.dll + + + + ..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/libplctag.NativeImport.Tests.NetFramework.DirectDependency/packages.config b/src/libplctag.NativeImport.Tests.NetFramework.DirectDependency/packages.config new file mode 100644 index 00000000..155230c8 --- /dev/null +++ b/src/libplctag.NativeImport.Tests.NetFramework.DirectDependency/packages.config @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/libplctag.NativeImport.Tests.NetFramework.TransitiveDependency/Properties/AssemblyInfo.cs b/src/libplctag.NativeImport.Tests.NetFramework.TransitiveDependency/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..4905f441 --- /dev/null +++ b/src/libplctag.NativeImport.Tests.NetFramework.TransitiveDependency/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("libplctag.NativeImport.Tests.NetFramework")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("libplctag.NativeImport.Tests.NetFramework")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("b8584170-3d77-4a0f-bd89-56c49aff6069")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/libplctag.NativeImport.Tests.NetFramework.TransitiveDependency/Test.cs b/src/libplctag.NativeImport.Tests.NetFramework.TransitiveDependency/Test.cs new file mode 100644 index 00000000..3b1fbdaa --- /dev/null +++ b/src/libplctag.NativeImport.Tests.NetFramework.TransitiveDependency/Test.cs @@ -0,0 +1,25 @@ +// Copyright (c) libplctag.NET contributors +// https://github.com/libplctag/libplctag.NET +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace libplctag.NativeImport.Tests.NetFramework.TransitiveDependency +{ + [TestClass] + public class Test + { + [TestMethod] + public void Can_execute_native_methods() + { + // The test is succesful if this does not throw + var output = LibPlcTag.IsRequiredVersion(0, 0, 0); + + // The below is redundant but is used to prove to the reader that the test works + Assert.IsTrue(true); + } + } +} diff --git a/src/libplctag.NativeImport.Tests.NetFramework.TransitiveDependency/app.config b/src/libplctag.NativeImport.Tests.NetFramework.TransitiveDependency/app.config new file mode 100644 index 00000000..dfb9dea8 --- /dev/null +++ b/src/libplctag.NativeImport.Tests.NetFramework.TransitiveDependency/app.config @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/libplctag.NativeImport.Tests.NetFramework.TransitiveDependency/libplctag.NativeImport.Tests.NetFramework.TransitiveDependency.csproj b/src/libplctag.NativeImport.Tests.NetFramework.TransitiveDependency/libplctag.NativeImport.Tests.NetFramework.TransitiveDependency.csproj new file mode 100644 index 00000000..af1b17b7 --- /dev/null +++ b/src/libplctag.NativeImport.Tests.NetFramework.TransitiveDependency/libplctag.NativeImport.Tests.NetFramework.TransitiveDependency.csproj @@ -0,0 +1,147 @@ + + + + + + + + + + Debug + AnyCPU + {E5CA2CC4-D572-4606-8C7F-CE14B6A5BA4D} + Library + Properties + libplctag.NativeImport.Tests.NetFramework.TransitiveDependency + libplctag.NativeImport.Tests.NetFramework.TransitiveDependency + v4.7.2 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\libplctag.1.5.2\lib\net472\libplctag.dll + True + + + ..\packages\libplctag.NativeImport.1.0.41\lib\net472\libplctag.NativeImport.dll + True + + + ..\packages\Microsoft.ApplicationInsights.2.22.0\lib\net46\Microsoft.ApplicationInsights.dll + + + + ..\packages\Microsoft.Testing.Extensions.Telemetry.1.2.1\lib\netstandard2.0\Microsoft.Testing.Extensions.Telemetry.dll + + + ..\packages\Microsoft.Testing.Extensions.TrxReport.Abstractions.1.2.1\lib\netstandard2.0\Microsoft.Testing.Extensions.TrxReport.Abstractions.dll + + + ..\packages\Microsoft.Testing.Extensions.VSTestBridge.1.2.1\lib\netstandard2.0\Microsoft.Testing.Extensions.VSTestBridge.dll + + + ..\packages\Microsoft.Testing.Platform.1.2.1\lib\netstandard2.0\Microsoft.Testing.Platform.dll + + + ..\packages\Microsoft.Testing.Platform.MSBuild.1.2.1\lib\netstandard2.0\Microsoft.Testing.Platform.MSBuild.dll + + + ..\packages\Microsoft.TestPlatform.ObjectModel.17.10.0\lib\net462\Microsoft.TestPlatform.CoreUtilities.dll + + + ..\packages\Microsoft.TestPlatform.ObjectModel.17.10.0\lib\net462\Microsoft.TestPlatform.PlatformAbstractions.dll + + + ..\packages\Microsoft.TestPlatform.ObjectModel.17.10.0\lib\net462\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll + + + ..\packages\MSTest.TestFramework.3.4.3\lib\net462\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.3.4.3\lib\net462\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + ..\packages\NuGet.Frameworks.6.10.1\lib\net472\NuGet.Frameworks.dll + + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + ..\packages\System.Collections.Immutable.8.0.0\lib\net462\System.Collections.Immutable.dll + + + + + ..\packages\System.Diagnostics.DiagnosticSource.8.0.1\lib\net462\System.Diagnostics.DiagnosticSource.dll + + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Reflection.Metadata.8.0.0\lib\net462\System.Reflection.Metadata.dll + + + + ..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/libplctag.NativeImport.Tests.NetFramework.TransitiveDependency/packages.config b/src/libplctag.NativeImport.Tests.NetFramework.TransitiveDependency/packages.config new file mode 100644 index 00000000..9ba3f9f8 --- /dev/null +++ b/src/libplctag.NativeImport.Tests.NetFramework.TransitiveDependency/packages.config @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/libplctag.NativeImport.Tests/UnitTest1.cs b/src/libplctag.NativeImport.Tests/UnitTest1.cs deleted file mode 100644 index 3cf88c9c..00000000 --- a/src/libplctag.NativeImport.Tests/UnitTest1.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) libplctag.NET contributors -// https://github.com/libplctag/libplctag.NET -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.Linq; -using System.Threading.Tasks; -using Xunit; - -namespace libplctag.NativeImport.Tests -{ - public class UnitTest1 - { - [Fact] - public void Test_Dll_Load() - { - // The simplest way to check the Dll is working is use the decode error API which returns a string - var output = plctag.plc_tag_decode_error(0); - Assert.Equal("PLCTAG_STATUS_OK", output); - } - - [Fact] - public void Parallel_Dll_Load() - { - Task.WaitAll(Enumerable.Range(0, 1000000).Select(i => Task.Run(async () => - { - await Task.Delay(1000); - plctag.plc_tag_check_lib_version(0, 0, 0); - })).ToArray()); - } - } -} diff --git a/src/libplctag.NativeImport/LibraryExtractor.cs b/src/libplctag.NativeImport/LibraryExtractor.cs deleted file mode 100644 index 4695a269..00000000 --- a/src/libplctag.NativeImport/LibraryExtractor.cs +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright (c) libplctag.NET contributors -// https://github.com/libplctag/libplctag.NET -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using System; -using System.IO; -using System.Reflection; -using System.Runtime.InteropServices; - -namespace libplctag.NativeImport -{ - class LibraryExtractor - { - - public static void Init(bool forceExtract = false) - { - - var extractDirectory = GetExtractDirectory(); - - if (forceExtract || !LibraryExists(extractDirectory)) - { - ExtractAppropriateLibraryToDirectory(extractDirectory); - } - - } - - static bool LibraryExists(string folder) - { - var library = GetAppropriateLibraryInfo(); - return File.Exists(Path.Combine(folder, library.FileName)); - } - - static string GetExtractDirectory() - { - return AppContext.BaseDirectory; - } - - static void ExtractAppropriateLibraryToDirectory(string outputDirectory) - { - var library = GetAppropriateLibraryInfo(); - var embeddedResource = GetEmbeddedResource(library.ResourceName); - - if (embeddedResource == null) throw new TypeLoadException("Appropriate native library is not embedded in this wrapper library"); - - var extractPath = Path.Combine(outputDirectory, library.FileName); - File.WriteAllBytes(extractPath, embeddedResource); - } - - static LibraryInfo GetAppropriateLibraryInfo() - { - - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && RuntimeInformation.ProcessArchitecture == Architecture.X86) - return new LibraryInfo("libplctag.NativeImport.runtime.win_x86", "plctag.dll"); - - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && RuntimeInformation.ProcessArchitecture == Architecture.X64) - return new LibraryInfo("libplctag.NativeImport.runtime.win_x64", "plctag.dll"); - - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && RuntimeInformation.ProcessArchitecture == Architecture.Arm) - return new LibraryInfo("libplctag.NativeImport.runtime.win_ARM", "plctag.dll"); - - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && RuntimeInformation.ProcessArchitecture == Architecture.Arm64) - return new LibraryInfo("libplctag.NativeImport.runtime.win_ARM64", "plctag.dll"); - - - - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && RuntimeInformation.ProcessArchitecture == Architecture.X86) - return new LibraryInfo("libplctag.NativeImport.runtime.linux_x86", "libplctag.so"); - - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && RuntimeInformation.ProcessArchitecture == Architecture.X64) - return new LibraryInfo("libplctag.NativeImport.runtime.linux_x64", "libplctag.so"); - - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && RuntimeInformation.ProcessArchitecture == Architecture.Arm) - return new LibraryInfo("libplctag.NativeImport.runtime.linux_ARM", "libplctag.so"); - - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && RuntimeInformation.ProcessArchitecture == Architecture.Arm64) - return new LibraryInfo("libplctag.NativeImport.runtime.linux_ARM64", "libplctag.so"); - - - - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && RuntimeInformation.ProcessArchitecture == Architecture.X64) - return new LibraryInfo("libplctag.NativeImport.runtime.osx_x64", "libplctag.dylib"); - - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && RuntimeInformation.ProcessArchitecture == Architecture.Arm64) - return new LibraryInfo("libplctag.NativeImport.runtime.osx_ARM64", "libplctag.dylib"); - - else - throw new TypeLoadException("Unknown platform"); - - } - - static byte[] GetEmbeddedResource(string resourceName) - { - - if (resourceName == null) return null; - - var assembly = Assembly.GetExecutingAssembly(); - using (Stream stream = assembly.GetManifestResourceStream(resourceName)) - { - if (stream == null) return null; - byte[] resource = new byte[stream.Length]; - stream.Read(resource, 0, resource.Length); - return resource; - } - } - - class LibraryInfo - { - public string ResourceName { get; set; } - public string FileName { get; set; } - - public LibraryInfo(string resourceNameWithoutFileName, string fileName) - { - ResourceName = resourceNameWithoutFileName == null ? null : $"{resourceNameWithoutFileName}.{fileName}"; - FileName = fileName; - } - } - - } -} diff --git a/src/libplctag.NativeImport/NativeMethods.cs b/src/libplctag.NativeImport/NativeMethods.cs index d34cbfcf..f4f8d760 100644 --- a/src/libplctag.NativeImport/NativeMethods.cs +++ b/src/libplctag.NativeImport/NativeMethods.cs @@ -8,6 +8,7 @@ using System; using System.Runtime.InteropServices; using System.Text; +using static libplctag.NativeImport.plctag; namespace libplctag.NativeImport { @@ -17,6 +18,30 @@ static class NativeMethods const string DLL_NAME = "plctag"; + static NativeMethods() + { +#if NET472_OR_GREATER + // Assume we're running on Windows because .NET Framework is not supported on other platforms + string executingDirectory = System.IO.Path.GetDirectoryName(typeof(NativeMethods).Assembly.Location); + string system = Environment.Is64BitProcess ? "X64" : "X86"; + string libDirectory = System.IO.Path.Combine (executingDirectory, system); + if (System.IO.Directory.Exists(libDirectory)) + { + SetDllDirectory(libDirectory); + } + else + { + SetDllDirectory(executingDirectory); + } +#endif + } + + + + [DllImport("kernel32.dll", SetLastError = true)] + private static extern bool SetDllDirectory(string lpPathName); + + [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_check_lib_version), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] public static extern int plc_tag_check_lib_version(int req_major, int req_minor, int req_patch); @@ -26,7 +51,7 @@ static class NativeMethods public static extern Int32 plc_tag_create([MarshalAs(UnmanagedType.LPStr)] string lpString, int timeout); [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_create_ex), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, CharSet = CharSet.Ansi)] - public static extern Int32 plc_tag_create_ex([MarshalAs(UnmanagedType.LPStr)] string lpString, plctag.callback_func_ex func, IntPtr userdata, int timeout); + public static extern Int32 plc_tag_create_ex([MarshalAs(UnmanagedType.LPStr)] string lpString, callback_func_ex func, IntPtr userdata, int timeout); [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_destroy), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] @@ -38,11 +63,11 @@ static class NativeMethods [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_register_callback), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern int plc_tag_register_callback(Int32 tag_id, plctag.callback_func func); + public static extern int plc_tag_register_callback(Int32 tag_id, callback_func func); [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_register_callback_ex), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern int plc_tag_register_callback_ex(Int32 tag_id, plctag.callback_func_ex func, IntPtr userdata); + public static extern int plc_tag_register_callback_ex(Int32 tag_id, callback_func_ex func, IntPtr userdata); [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_unregister_callback), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] @@ -53,7 +78,7 @@ static class NativeMethods [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_register_logger), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern int plc_tag_register_logger(plctag.log_callback_func func); + public static extern int plc_tag_register_logger(log_callback_func func); [DllImport(DLL_NAME, EntryPoint = nameof(plc_tag_unregister_logger), CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] diff --git a/src/libplctag.NativeImport/libplctag.NativeImport.csproj b/src/libplctag.NativeImport/libplctag.NativeImport.csproj index 9b02e602..d051b858 100644 --- a/src/libplctag.NativeImport/libplctag.NativeImport.csproj +++ b/src/libplctag.NativeImport/libplctag.NativeImport.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net47;net471;net472;net48;net481 libplctag.NativeImport libplctag.NativeImport libplctag.NativeImport @@ -19,16 +19,7 @@ - - - - - - - - - - + @@ -47,4 +38,11 @@ + + + + + + + diff --git a/src/libplctag.NativeImport/libplctag.NativeImport.props b/src/libplctag.NativeImport/libplctag.NativeImport.props new file mode 100644 index 00000000..0dfb6a31 --- /dev/null +++ b/src/libplctag.NativeImport/libplctag.NativeImport.props @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/libplctag.NativeImport/libplctag.NativeImport.targets b/src/libplctag.NativeImport/libplctag.NativeImport.targets new file mode 100644 index 00000000..a5208aa7 --- /dev/null +++ b/src/libplctag.NativeImport/libplctag.NativeImport.targets @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/src/libplctag.NativeImport/plctag.cs b/src/libplctag.NativeImport/plctag.cs index c72a618f..0bf73682 100644 --- a/src/libplctag.NativeImport/plctag.cs +++ b/src/libplctag.NativeImport/plctag.cs @@ -21,51 +21,6 @@ namespace libplctag.NativeImport public static class plctag { - - - static private bool _forceExtractLibrary = true; - - /// - /// During initialization, this package extracts to disk the appropriate native library. - /// By default, it will overwrite files with the same filename (plctag.dll, libplctag.so, or libplctag.dylib). - /// If you wish to disable this behaviour and use a different native library (e.g. one that you've compiled yourself, or a pre-release), you can disable the Force Extract feature by setting this value to false. - /// - static public bool ForceExtractLibrary - { - get => _forceExtractLibrary; - set - { - if (libraryAlreadyInitialized) - throw new InvalidOperationException("Library already initialized"); - _forceExtractLibrary = value; - } - } - - static private bool libraryAlreadyInitialized = false; - static object _libraryExtractLocker = new object(); - private static void ExtractLibraryIfRequired() - { - // Non-blocking check - // Except during startup, this will be hit 100% of the time - if(!libraryAlreadyInitialized) - { - - // Blocking check - // This is hit if multiple threads simultaneously try to initialize the library - lock (_libraryExtractLocker) - { - if (!libraryAlreadyInitialized) - { - LibraryExtractor.Init(ForceExtractLibrary); - libraryAlreadyInitialized = true; - } - } - } - } - - - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void callback_func(Int32 tag_id, Int32 event_id, Int32 status); @@ -75,271 +30,224 @@ private static void ExtractLibraryIfRequired() [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] public delegate void log_callback_func(Int32 tag_id, int debug_level, [MarshalAs(UnmanagedType.LPStr)] string message); - - public static int plc_tag_check_lib_version(int req_major, int req_minor, int req_patch) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_check_lib_version(req_major, req_minor, req_patch); } - public static Int32 plc_tag_create([MarshalAs(UnmanagedType.LPStr)] string lpString, int timeout) + public static Int32 plc_tag_create(string lpString, int timeout) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_create(lpString, timeout); } - public static Int32 plc_tag_create_ex([MarshalAs(UnmanagedType.LPStr)] string lpString, callback_func_ex func, IntPtr userdata, int timeout) + public static Int32 plc_tag_create_ex(string lpString, callback_func_ex func, IntPtr userdata, int timeout) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_create_ex(lpString, func, userdata, timeout); } public static int plc_tag_destroy(Int32 tag) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_destroy(tag); } public static int plc_tag_shutdown() { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_shutdown(); } public static int plc_tag_register_callback(Int32 tag_id, callback_func func) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_register_callback(tag_id, func); } public static int plc_tag_register_callback_ex(Int32 tag_id, callback_func_ex func, IntPtr userdata) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_register_callback_ex(tag_id, func, userdata); } public static int plc_tag_unregister_callback(Int32 tag_id) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_unregister_callback(tag_id); } public static int plc_tag_register_logger(log_callback_func func) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_register_logger(func); } public static int plc_tag_unregister_logger(Int32 tag_id) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_unregister_logger(tag_id); } public static int plc_tag_lock(Int32 tag) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_lock(tag); } public static int plc_tag_unlock(Int32 tag) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_unlock(tag); } public static int plc_tag_status(Int32 tag) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_status(tag); } public static string plc_tag_decode_error(int err) { - ExtractLibraryIfRequired(); return Marshal.PtrToStringAnsi(NativeMethods.plc_tag_decode_error(err)); } public static int plc_tag_read(Int32 tag, int timeout) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_read(tag, timeout); } public static int plc_tag_write(Int32 tag, int timeout) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_write(tag, timeout); } public static int plc_tag_get_size(Int32 tag) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_get_size(tag); } public static int plc_tag_set_size(Int32 tag, int new_size) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_set_size(tag, new_size); } public static int plc_tag_abort(Int32 tag) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_abort(tag); } public static int plc_tag_get_int_attribute(Int32 tag, string attrib_name, int default_value) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_get_int_attribute(tag, attrib_name, default_value); } public static int plc_tag_set_int_attribute(Int32 tag, string attrib_name, int new_value) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_set_int_attribute(tag, attrib_name, new_value); } public static int plc_tag_get_byte_array_attribute(Int32 tag, string attrib_name, byte[] buffer, int buffer_length) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_get_byte_array_attribute(tag, attrib_name, buffer, buffer_length); } public static UInt64 plc_tag_get_uint64(Int32 tag, int offset) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_get_uint64(tag, offset); } public static Int64 plc_tag_get_int64(Int32 tag, int offset) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_get_int64(tag, offset); } public static int plc_tag_set_uint64(Int32 tag, int offset, UInt64 val) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_set_uint64(tag, offset, val); } public static int plc_tag_set_int64(Int32 tag, int offset, Int64 val) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_set_int64(tag, offset, val); } public static double plc_tag_get_float64(Int32 tag, int offset) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_get_float64(tag, offset); } public static int plc_tag_set_float64(Int32 tag, int offset, double val) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_set_float64(tag, offset, val); } public static UInt32 plc_tag_get_uint32(Int32 tag, int offset) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_get_uint32(tag, offset); } public static Int32 plc_tag_get_int32(Int32 tag, int offset) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_get_int32(tag, offset); } public static int plc_tag_set_uint32(Int32 tag, int offset, UInt32 val) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_set_uint32(tag, offset, val); } public static int plc_tag_set_int32(Int32 tag, int offset, Int32 val) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_set_int32(tag, offset, val); } public static float plc_tag_get_float32(Int32 tag, int offset) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_get_float32(tag, offset); } public static int plc_tag_set_float32(Int32 tag, int offset, float val) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_set_float32(tag, offset, val); } public static UInt16 plc_tag_get_uint16(Int32 tag, int offset) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_get_uint16(tag, offset); } public static Int16 plc_tag_get_int16(Int32 tag, int offset) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_get_int16(tag, offset); } public static int plc_tag_set_uint16(Int32 tag, int offset, UInt16 val) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_set_uint16(tag, offset, val); } public static int plc_tag_set_int16(Int32 tag, int offset, Int16 val) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_set_int16(tag, offset, val); } public static byte plc_tag_get_uint8(Int32 tag, int offset) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_get_uint8(tag, offset); } public static sbyte plc_tag_get_int8(Int32 tag, int offset) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_get_int8(tag, offset); } public static int plc_tag_set_uint8(Int32 tag, int offset, byte val) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_set_uint8(tag, offset, val); } public static int plc_tag_set_int8(Int32 tag, int offset, sbyte val) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_set_int8(tag, offset, val); } public static int plc_tag_get_bit(Int32 tag, int offset_bit) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_get_bit(tag, offset_bit); } public static int plc_tag_set_bit(Int32 tag, int offset_bit, int val) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_set_bit(tag, offset_bit, val); } public static void plc_tag_set_debug_level(int debug_level) { - ExtractLibraryIfRequired(); NativeMethods.plc_tag_set_debug_level(debug_level); } @@ -347,44 +255,37 @@ public static void plc_tag_set_debug_level(int debug_level) public static int plc_tag_get_string(Int32 tag_id, int string_start_offset, StringBuilder buffer, int buffer_length) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_get_string(tag_id, string_start_offset, buffer, buffer_length); } public static int plc_tag_set_string(Int32 tag_id, int string_start_offset, string string_val) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_set_string(tag_id, string_start_offset, string_val); } public static int plc_tag_get_string_length(Int32 tag_id, int string_start_offset) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_get_string_length(tag_id, string_start_offset); } public static int plc_tag_get_string_capacity(Int32 tag_id, int string_start_offset) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_get_string_capacity(tag_id, string_start_offset); } public static int plc_tag_get_string_total_length(Int32 tag_id, int string_start_offset) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_get_string_total_length(tag_id, string_start_offset); } public static int plc_tag_get_raw_bytes(Int32 tag_id, int start_offset, byte[] buffer, int buffer_length) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_get_raw_bytes(tag_id, start_offset, buffer, buffer_length); } public static int plc_tag_set_raw_bytes(Int32 tag_id, int start_offset, byte[] buffer, int buffer_length) { - ExtractLibraryIfRequired(); return NativeMethods.plc_tag_set_raw_bytes(tag_id, start_offset, buffer, buffer_length); } diff --git a/src/libplctag.NativeImport/runtime/linux_ARM/libplctag.so b/src/libplctag.NativeImport/runtimes/linux-arm/native/libplctag.so similarity index 100% rename from src/libplctag.NativeImport/runtime/linux_ARM/libplctag.so rename to src/libplctag.NativeImport/runtimes/linux-arm/native/libplctag.so diff --git a/src/libplctag.NativeImport/runtime/linux_ARM64/libplctag.so b/src/libplctag.NativeImport/runtimes/linux-arm64/native/libplctag.so similarity index 100% rename from src/libplctag.NativeImport/runtime/linux_ARM64/libplctag.so rename to src/libplctag.NativeImport/runtimes/linux-arm64/native/libplctag.so diff --git a/src/libplctag.NativeImport/runtime/linux_x64/libplctag.so b/src/libplctag.NativeImport/runtimes/linux-x64/native/libplctag.so similarity index 100% rename from src/libplctag.NativeImport/runtime/linux_x64/libplctag.so rename to src/libplctag.NativeImport/runtimes/linux-x64/native/libplctag.so diff --git a/src/libplctag.NativeImport/runtime/linux_x86/libplctag.so b/src/libplctag.NativeImport/runtimes/linux-x86/native/libplctag.so similarity index 100% rename from src/libplctag.NativeImport/runtime/linux_x86/libplctag.so rename to src/libplctag.NativeImport/runtimes/linux-x86/native/libplctag.so diff --git a/src/libplctag.NativeImport/runtime/osx_ARM64/libplctag.dylib b/src/libplctag.NativeImport/runtimes/osx-arm64/native/libplctag.dylib similarity index 100% rename from src/libplctag.NativeImport/runtime/osx_ARM64/libplctag.dylib rename to src/libplctag.NativeImport/runtimes/osx-arm64/native/libplctag.dylib diff --git a/src/libplctag.NativeImport/runtime/osx_x64/libplctag.dylib b/src/libplctag.NativeImport/runtimes/osx-x64/native/libplctag.dylib similarity index 100% rename from src/libplctag.NativeImport/runtime/osx_x64/libplctag.dylib rename to src/libplctag.NativeImport/runtimes/osx-x64/native/libplctag.dylib diff --git a/src/libplctag.NativeImport/runtime/win_ARM/plctag.dll b/src/libplctag.NativeImport/runtimes/win-arm/native/plctag.dll similarity index 100% rename from src/libplctag.NativeImport/runtime/win_ARM/plctag.dll rename to src/libplctag.NativeImport/runtimes/win-arm/native/plctag.dll diff --git a/src/libplctag.NativeImport/runtime/win_ARM64/plctag.dll b/src/libplctag.NativeImport/runtimes/win-arm64/native/plctag.dll similarity index 100% rename from src/libplctag.NativeImport/runtime/win_ARM64/plctag.dll rename to src/libplctag.NativeImport/runtimes/win-arm64/native/plctag.dll diff --git a/src/libplctag.NativeImport/runtime/win_x64/plctag.dll b/src/libplctag.NativeImport/runtimes/win-x64/native/plctag.dll similarity index 100% rename from src/libplctag.NativeImport/runtime/win_x64/plctag.dll rename to src/libplctag.NativeImport/runtimes/win-x64/native/plctag.dll diff --git a/src/libplctag.NativeImport/runtime/win_x86/plctag.dll b/src/libplctag.NativeImport/runtimes/win-x86/native/plctag.dll similarity index 100% rename from src/libplctag.NativeImport/runtime/win_x86/plctag.dll rename to src/libplctag.NativeImport/runtimes/win-x86/native/plctag.dll diff --git a/src/libplctag.Tests/libplctag.Tests.csproj b/src/libplctag.Tests/libplctag.Tests.csproj index 1a31533a..6e48ea9c 100644 --- a/src/libplctag.Tests/libplctag.Tests.csproj +++ b/src/libplctag.Tests/libplctag.Tests.csproj @@ -7,14 +7,14 @@ - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/libplctag.sln b/src/libplctag.sln index 964a0de7..2283c9e6 100644 --- a/src/libplctag.sln +++ b/src/libplctag.sln @@ -7,11 +7,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "libplctag", "libplctag\libp EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "libplctag.NativeImport", "libplctag.NativeImport\libplctag.NativeImport.csproj", "{1D976518-8766-44DF-8DF9-636C8BD6FA24}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "libplctag.NativeImport.Tests", "libplctag.NativeImport.Tests\libplctag.NativeImport.Tests.csproj", "{59D7EBF0-6EBB-4D07-B136-8E80B018C81A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "libplctag.Tests", "libplctag.Tests\libplctag.Tests.csproj", "{2FCB9157-85F9-4631-838D-89CAC323397E}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "libplctag.NativeImport.Benchmarks", "libplctag.NativeImport.Benchmarks\libplctag.NativeImport.Benchmarks.csproj", "{547E83B4-75E2-42BC-A118-FF41BEF51339}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "libplctag.NativeImport.Tests.NetCore.DirectDependency", "libplctag.NativeImport.Tests.NetCore.DirectDependency\libplctag.NativeImport.Tests.NetCore.DirectDependency.csproj", "{F61BD0F4-A382-48EC-B586-3E02466BE98A}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "libplctag.Tests", "libplctag.Tests\libplctag.Tests.csproj", "{2FCB9157-85F9-4631-838D-89CAC323397E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "libplctag.NativeImport.Tests.NetCore.TransitiveDependency", "libplctag.NativeImport.Tests.NetCore.TransitiveDependency\libplctag.NativeImport.Tests.NetCore.TransitiveDependency.csproj", "{4D7DA60C-2B66-4E12-986F-F2A901B2F7E0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "libplctag.NativeImport.Tests.NetFramework.DirectDependency", "libplctag.NativeImport.Tests.NetFramework.DirectDependency\libplctag.NativeImport.Tests.NetFramework.DirectDependency.csproj", "{B8584170-3D77-4A0F-BD89-56C49AFF6069}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "libplctag.NativeImport.Tests.NetFramework.TransitiveDependency", "libplctag.NativeImport.Tests.NetFramework.TransitiveDependency\libplctag.NativeImport.Tests.NetFramework.TransitiveDependency.csproj", "{E5CA2CC4-D572-4606-8C7F-CE14B6A5BA4D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -47,30 +51,6 @@ Global {1D976518-8766-44DF-8DF9-636C8BD6FA24}.Release|x64.Build.0 = Release|Any CPU {1D976518-8766-44DF-8DF9-636C8BD6FA24}.Release|x86.ActiveCfg = Release|Any CPU {1D976518-8766-44DF-8DF9-636C8BD6FA24}.Release|x86.Build.0 = Release|Any CPU - {59D7EBF0-6EBB-4D07-B136-8E80B018C81A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {59D7EBF0-6EBB-4D07-B136-8E80B018C81A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {59D7EBF0-6EBB-4D07-B136-8E80B018C81A}.Debug|x64.ActiveCfg = Debug|Any CPU - {59D7EBF0-6EBB-4D07-B136-8E80B018C81A}.Debug|x64.Build.0 = Debug|Any CPU - {59D7EBF0-6EBB-4D07-B136-8E80B018C81A}.Debug|x86.ActiveCfg = Debug|Any CPU - {59D7EBF0-6EBB-4D07-B136-8E80B018C81A}.Debug|x86.Build.0 = Debug|Any CPU - {59D7EBF0-6EBB-4D07-B136-8E80B018C81A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {59D7EBF0-6EBB-4D07-B136-8E80B018C81A}.Release|Any CPU.Build.0 = Release|Any CPU - {59D7EBF0-6EBB-4D07-B136-8E80B018C81A}.Release|x64.ActiveCfg = Release|Any CPU - {59D7EBF0-6EBB-4D07-B136-8E80B018C81A}.Release|x64.Build.0 = Release|Any CPU - {59D7EBF0-6EBB-4D07-B136-8E80B018C81A}.Release|x86.ActiveCfg = Release|Any CPU - {59D7EBF0-6EBB-4D07-B136-8E80B018C81A}.Release|x86.Build.0 = Release|Any CPU - {547E83B4-75E2-42BC-A118-FF41BEF51339}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {547E83B4-75E2-42BC-A118-FF41BEF51339}.Debug|Any CPU.Build.0 = Debug|Any CPU - {547E83B4-75E2-42BC-A118-FF41BEF51339}.Debug|x64.ActiveCfg = Debug|Any CPU - {547E83B4-75E2-42BC-A118-FF41BEF51339}.Debug|x64.Build.0 = Debug|Any CPU - {547E83B4-75E2-42BC-A118-FF41BEF51339}.Debug|x86.ActiveCfg = Debug|Any CPU - {547E83B4-75E2-42BC-A118-FF41BEF51339}.Debug|x86.Build.0 = Debug|Any CPU - {547E83B4-75E2-42BC-A118-FF41BEF51339}.Release|Any CPU.ActiveCfg = Release|Any CPU - {547E83B4-75E2-42BC-A118-FF41BEF51339}.Release|Any CPU.Build.0 = Release|Any CPU - {547E83B4-75E2-42BC-A118-FF41BEF51339}.Release|x64.ActiveCfg = Release|Any CPU - {547E83B4-75E2-42BC-A118-FF41BEF51339}.Release|x64.Build.0 = Release|Any CPU - {547E83B4-75E2-42BC-A118-FF41BEF51339}.Release|x86.ActiveCfg = Release|Any CPU - {547E83B4-75E2-42BC-A118-FF41BEF51339}.Release|x86.Build.0 = Release|Any CPU {2FCB9157-85F9-4631-838D-89CAC323397E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2FCB9157-85F9-4631-838D-89CAC323397E}.Debug|Any CPU.Build.0 = Debug|Any CPU {2FCB9157-85F9-4631-838D-89CAC323397E}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -83,6 +63,54 @@ Global {2FCB9157-85F9-4631-838D-89CAC323397E}.Release|x64.Build.0 = Release|Any CPU {2FCB9157-85F9-4631-838D-89CAC323397E}.Release|x86.ActiveCfg = Release|Any CPU {2FCB9157-85F9-4631-838D-89CAC323397E}.Release|x86.Build.0 = Release|Any CPU + {F61BD0F4-A382-48EC-B586-3E02466BE98A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F61BD0F4-A382-48EC-B586-3E02466BE98A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F61BD0F4-A382-48EC-B586-3E02466BE98A}.Debug|x64.ActiveCfg = Debug|Any CPU + {F61BD0F4-A382-48EC-B586-3E02466BE98A}.Debug|x64.Build.0 = Debug|Any CPU + {F61BD0F4-A382-48EC-B586-3E02466BE98A}.Debug|x86.ActiveCfg = Debug|Any CPU + {F61BD0F4-A382-48EC-B586-3E02466BE98A}.Debug|x86.Build.0 = Debug|Any CPU + {F61BD0F4-A382-48EC-B586-3E02466BE98A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F61BD0F4-A382-48EC-B586-3E02466BE98A}.Release|Any CPU.Build.0 = Release|Any CPU + {F61BD0F4-A382-48EC-B586-3E02466BE98A}.Release|x64.ActiveCfg = Release|Any CPU + {F61BD0F4-A382-48EC-B586-3E02466BE98A}.Release|x64.Build.0 = Release|Any CPU + {F61BD0F4-A382-48EC-B586-3E02466BE98A}.Release|x86.ActiveCfg = Release|Any CPU + {F61BD0F4-A382-48EC-B586-3E02466BE98A}.Release|x86.Build.0 = Release|Any CPU + {4D7DA60C-2B66-4E12-986F-F2A901B2F7E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4D7DA60C-2B66-4E12-986F-F2A901B2F7E0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4D7DA60C-2B66-4E12-986F-F2A901B2F7E0}.Debug|x64.ActiveCfg = Debug|Any CPU + {4D7DA60C-2B66-4E12-986F-F2A901B2F7E0}.Debug|x64.Build.0 = Debug|Any CPU + {4D7DA60C-2B66-4E12-986F-F2A901B2F7E0}.Debug|x86.ActiveCfg = Debug|Any CPU + {4D7DA60C-2B66-4E12-986F-F2A901B2F7E0}.Debug|x86.Build.0 = Debug|Any CPU + {4D7DA60C-2B66-4E12-986F-F2A901B2F7E0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4D7DA60C-2B66-4E12-986F-F2A901B2F7E0}.Release|Any CPU.Build.0 = Release|Any CPU + {4D7DA60C-2B66-4E12-986F-F2A901B2F7E0}.Release|x64.ActiveCfg = Release|Any CPU + {4D7DA60C-2B66-4E12-986F-F2A901B2F7E0}.Release|x64.Build.0 = Release|Any CPU + {4D7DA60C-2B66-4E12-986F-F2A901B2F7E0}.Release|x86.ActiveCfg = Release|Any CPU + {4D7DA60C-2B66-4E12-986F-F2A901B2F7E0}.Release|x86.Build.0 = Release|Any CPU + {B8584170-3D77-4A0F-BD89-56C49AFF6069}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B8584170-3D77-4A0F-BD89-56C49AFF6069}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B8584170-3D77-4A0F-BD89-56C49AFF6069}.Debug|x64.ActiveCfg = Debug|Any CPU + {B8584170-3D77-4A0F-BD89-56C49AFF6069}.Debug|x64.Build.0 = Debug|Any CPU + {B8584170-3D77-4A0F-BD89-56C49AFF6069}.Debug|x86.ActiveCfg = Debug|Any CPU + {B8584170-3D77-4A0F-BD89-56C49AFF6069}.Debug|x86.Build.0 = Debug|Any CPU + {B8584170-3D77-4A0F-BD89-56C49AFF6069}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B8584170-3D77-4A0F-BD89-56C49AFF6069}.Release|Any CPU.Build.0 = Release|Any CPU + {B8584170-3D77-4A0F-BD89-56C49AFF6069}.Release|x64.ActiveCfg = Release|Any CPU + {B8584170-3D77-4A0F-BD89-56C49AFF6069}.Release|x64.Build.0 = Release|Any CPU + {B8584170-3D77-4A0F-BD89-56C49AFF6069}.Release|x86.ActiveCfg = Release|Any CPU + {B8584170-3D77-4A0F-BD89-56C49AFF6069}.Release|x86.Build.0 = Release|Any CPU + {E5CA2CC4-D572-4606-8C7F-CE14B6A5BA4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E5CA2CC4-D572-4606-8C7F-CE14B6A5BA4D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E5CA2CC4-D572-4606-8C7F-CE14B6A5BA4D}.Debug|x64.ActiveCfg = Debug|Any CPU + {E5CA2CC4-D572-4606-8C7F-CE14B6A5BA4D}.Debug|x64.Build.0 = Debug|Any CPU + {E5CA2CC4-D572-4606-8C7F-CE14B6A5BA4D}.Debug|x86.ActiveCfg = Debug|Any CPU + {E5CA2CC4-D572-4606-8C7F-CE14B6A5BA4D}.Debug|x86.Build.0 = Debug|Any CPU + {E5CA2CC4-D572-4606-8C7F-CE14B6A5BA4D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E5CA2CC4-D572-4606-8C7F-CE14B6A5BA4D}.Release|Any CPU.Build.0 = Release|Any CPU + {E5CA2CC4-D572-4606-8C7F-CE14B6A5BA4D}.Release|x64.ActiveCfg = Release|Any CPU + {E5CA2CC4-D572-4606-8C7F-CE14B6A5BA4D}.Release|x64.Build.0 = Release|Any CPU + {E5CA2CC4-D572-4606-8C7F-CE14B6A5BA4D}.Release|x86.ActiveCfg = Release|Any CPU + {E5CA2CC4-D572-4606-8C7F-CE14B6A5BA4D}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/libplctag/INativeTag.cs b/src/libplctag/INativeTag.cs index 3f889052..c50ff706 100644 --- a/src/libplctag/INativeTag.cs +++ b/src/libplctag/INativeTag.cs @@ -5,10 +5,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using libplctag.NativeImport; using System; using System.Runtime.CompilerServices; using System.Text; +using static libplctag.NativeImport.plctag; [assembly: InternalsVisibleTo("libplctag.Tests")] @@ -21,7 +21,7 @@ interface INativeTag int plc_tag_abort(int tag); int plc_tag_check_lib_version(int req_major, int req_minor, int req_patch); int plc_tag_create(string lpString, int timeout); - int plc_tag_create_ex(string lpString, plctag.callback_func_ex func, IntPtr userdata, int timeout); + int plc_tag_create_ex(string lpString, callback_func_ex func, IntPtr userdata, int timeout); string plc_tag_decode_error(int err); int plc_tag_destroy(int tag); int plc_tag_get_bit(int tag, int offset_bit); @@ -42,8 +42,8 @@ interface INativeTag byte plc_tag_get_uint8(int tag, int offset); int plc_tag_lock(int tag); int plc_tag_read(int tag, int timeout); - int plc_tag_register_callback(int tag_id, plctag.callback_func func); - int plc_tag_register_logger(plctag.log_callback_func func); + int plc_tag_register_callback(int tag_id, callback_func func); + int plc_tag_register_logger(log_callback_func func); int plc_tag_set_bit(int tag, int offset_bit, int val); void plc_tag_set_debug_level(int debug_level); int plc_tag_set_float32(int tag, int offset, float val); diff --git a/src/libplctag/LibPlcTag.cs b/src/libplctag/LibPlcTag.cs index d4df91c5..16bc654f 100644 --- a/src/libplctag/LibPlcTag.cs +++ b/src/libplctag/LibPlcTag.cs @@ -7,6 +7,7 @@ using libplctag.NativeImport; using System; +using static libplctag.NativeImport.plctag; namespace libplctag { @@ -56,13 +57,13 @@ static public DebugLevel DebugLevel static readonly object logEventSubscriptionLock = new object(); static private event EventHandler logEvent; static bool alreadySubscribedToEvents = false; - static plctag.log_callback_func loggerDelegate; + static log_callback_func loggerDelegate; static private void ensureSubscribeToEvents() { if (alreadySubscribedToEvents) return; - loggerDelegate = new plctag.log_callback_func(invokeLogEvent); + loggerDelegate = new log_callback_func(invokeLogEvent); var statusAfterRegistration = (Status)_native.plc_tag_register_logger(loggerDelegate); if (statusAfterRegistration != Status.Ok) throw new LibPlcTagException(statusAfterRegistration); diff --git a/src/libplctag/NativeTagWrapper.cs b/src/libplctag/NativeTagWrapper.cs index ff37f17f..0fe3a825 100644 --- a/src/libplctag/NativeTagWrapper.cs +++ b/src/libplctag/NativeTagWrapper.cs @@ -13,6 +13,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; +using static libplctag.NativeImport.plctag; [assembly: InternalsVisibleTo("libplctag.Tests")] @@ -26,7 +27,7 @@ class NativeTagWrapper : IDisposable private static readonly TimeSpan maxTimeout = TimeSpan.FromMilliseconds(int.MaxValue); private int nativeTagHandle; - private libplctag.NativeImport.plctag.callback_func_ex coreLibCallbackFuncExDelegate; + private callback_func_ex coreLibCallbackFuncExDelegate; private bool _isDisposed = false; private bool _isInitialized = false; @@ -811,7 +812,7 @@ void SetUpEvents() Created += CreatedTaskCompleter; // Need to keep a reference to the delegate in memory so it doesn't get garbage collected - coreLibCallbackFuncExDelegate = new libplctag.NativeImport.plctag.callback_func_ex(coreLibEventCallback); + coreLibCallbackFuncExDelegate = new callback_func_ex(coreLibEventCallback); } diff --git a/src/libplctag/libplctag.csproj b/src/libplctag/libplctag.csproj index 317b8db4..8728a0af 100644 --- a/src/libplctag/libplctag.csproj +++ b/src/libplctag/libplctag.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net47;net471;net472;net48;net481 libplctag libplctag libplctag