Closed gfoidl closed 6 years ago
Orientate on https://github.com/gfoidl/CairoSharp
Type | Status |
---|---|
.net Core app (win-x64) | OK |
.net Core app (linux-x64) | OK |
.net Core lib | OK |
.net Standard lib | OK |
When targeting .net Full the native libs are not copied. This point has to be addressed or circumvented. For instance that the native libs are only used when running on .net Core.
This code
using System;
using System.Reflection;
using System.Runtime.Versioning;
namespace ClassLibrary1
{
public class Class1
{
public void Foo()
{
Console.WriteLine($"FrameworkDescription: {System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription}");
Console.WriteLine($"version: {GetNetCoreVersion()}");
Console.WriteLine($"TargetFrameworkName: {AppContext.TargetFrameworkName}");
Console.WriteLine($"FrameworkName: {Assembly.GetEntryAssembly()?.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName}");
Console.WriteLine($"FrameworkDisplayName: {Assembly.GetEntryAssembly()?.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkDisplayName}");
Console.WriteLine($"{nameof(IsRunningOnDotNetCore)}: {IsRunningOnDotNetCore}");
}
//---------------------------------------------------------------------
public static bool IsRunningOnDotNetCore =>
Type.GetType("System.Runtime.Loader.AssemblyLoadContext") != null;
//---------------------------------------------------------------------
public static string GetNetCoreVersion()
{
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];
return null;
}
}
}
produces on .net Core
FrameworkDescription: .NET Core 4.6.26020.03
version: 2.0.5
TargetFrameworkName:
FrameworkName: .NETCoreApp,Version=v2.0
FrameworkDisplayName:
IsRunningOnDotNetCore: True
and on .net Full (4.7.1)
FrameworkDescription: .NET Framework 4.7.2600.0
version:
TargetFrameworkName: .NETFramework,Version=v4.7.1
FrameworkName: .NETFramework,Version=v4.7.1
FrameworkDisplayName: .NET Framework 4.7.1
IsRunningOnDotNetCore: False
So all methods either get a attribute or load a type. Hence the cleares way is the one from IsRunningOnDotNetCore
, but this bears the potential disadvantage when the loaded type System.Runtime.Loader.AssemblyLoadContext
is ported to .net Full or any other platform that this approach will yield wrong results. So the way via FrameworkName is clear and should be followed.
Can be closed as the circumvent was done in #40, so no problem with the nuget package exists.
Don't know if it is correct, so check and potentially fix it.