Skip to content

Commit

Permalink
Merge pull request #1304 from shimat/net5detection
Browse files Browse the repository at this point in the history
Fix IsDotNetCore
  • Loading branch information
shimat authored Aug 17, 2021
2 parents 262dd42 + 5e60027 commit 5c23fb4
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/OpenCvSharp/Internal/PInvoke/WindowsLibraryLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public bool IsLibraryLoaded(string dllName)
}

/// <summary>
///
/// Determine if the OS is Windows
/// </summary>
/// <returns></returns>
public static bool IsCurrentPlatformSupported()
Expand All @@ -98,7 +98,7 @@ public static bool IsCurrentPlatformSupported()
}

/// <summary>
///
/// Determine if the runtime is .NET Core
/// </summary>
/// <returns></returns>
public static bool IsDotNetCore()
Expand All @@ -107,7 +107,8 @@ public static bool IsDotNetCore()
return false;
#else
// https://github.com/dotnet/corefx/blob/v2.1-preview1/src/CoreFx.Private.TestUtilities/src/System/PlatformDetection.cs
return RuntimeInformation.FrameworkDescription.StartsWith(".NET Core", StringComparison.Ordinal);
return Environment.Version.Major >= 5 ||
RuntimeInformation.FrameworkDescription.StartsWith(".NET Core", StringComparison.OrdinalIgnoreCase);
#endif
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions test/OpenCvSharp.Tests/system/WindowsLibraryLoaderTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#nullable enable

using OpenCvSharp.Internal;
using Xunit;

namespace OpenCvSharp.Tests
{
public class WindowsLibraryLoaderTest
{
[Fact]
public void IsDotNetCore()
{
#if NET48
Assert.False(WindowsLibraryLoader.IsDotNetCore());
#elif NETCOREAPP3_1_OR_GREATER
Assert.True(WindowsLibraryLoader.IsDotNetCore());
#else
throw new OpenCvSharpException("Unexpected environment.");
#endif
}
}
}

0 comments on commit 5c23fb4

Please sign in to comment.