8000 Move to only netstandard2.0 target · wtf3505-git/libgit2sharp@7ca3791 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7ca3791

Browse files
committed
Move to only netstandard2.0 target
1 parent a5ef816 commit 7ca3791

8 files changed

+6
-110
lines changed

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net46;net472;netcoreapp2.1</TargetFrameworks>
4+
<TargetFrameworks>net472;netcoreapp2.1</TargetFrameworks>
55
</PropertyGroup>
66

77
<ItemGroup>

LibGit2Sharp/Core/ManagedHttpSmartSubtransport.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#if !NET46
21
using System;
32
using System.IO;
43
using System.Linq;
@@ -271,4 +270,3 @@ protected override void Free()
271270
}
272271
}
273272
}
274-
#endif

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ internal static class NativeMethods
2626
private static NativeShutdownObject shutdownObject;
2727
#pragma warning restore 0414
2828

29-
#if !NET46
3029
private static SmartSubtransportRegistration<ManagedHttpSmartSubtransport> httpSubtransportRegistration;
3130
private static SmartSubtransportRegistration<ManagedHttpSmartSubtransport> httpsSubtransportRegistration;
32-
#endif
3331

3432
static NativeMethods()
3533
{
@@ -47,11 +45,8 @@ static NativeMethods()
4745
string nativeLibraryPath = GetGlobalSettingsNativeLibraryPath();
4846
if (nativeLibraryPath != null)
4947
{
50-
#if NET46
51-
if (Platform.OperatingSystem == OperatingSystemType.Windows)
52-
#else
5348
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
54-
#endif
49+
5550
{
5651
LoadWindowsLibrary(nativeLibraryPath);
5752
}
@@ -151,8 +146,6 @@ private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImpor
151146
return handle;
152147
}
153148

154-
#if NETFRAMEWORK
155-
#else
156149
// We cary a number of .so files for Linux which are linked against various
157150
// libc/OpenSSL libraries. Try them out.
158151
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
@@ -175,7 +168,6 @@ private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImpor
175168
}
176169
}
177170
}
178-
#endif
179171
}
180172
return handle;
181173
}
@@ -204,22 +196,19 @@ private static void InitializeNativeLibrary()
204196
shutdownObject = new NativeShutdownObject();
205197
}
206198

207-
#if !NET46
208199
// Configure the .NET HTTP(S) mechanism on the first initialization of the library in the current process.
209200
if (initCounter == 1 && Global A3E2 Settings.ManagedHttpSmartSubtransportEnabled)
210201
{
211202
httpSubtransportRegistration = GlobalSettings.RegisterDefaultSmartSubtransport<ManagedHttpSmartSubtransport>("http");
212203
httpsSubtransportRegistration = GlobalSettings.RegisterDefaultSmartSubtransport<ManagedHttpSmartSubtransport>("https");
213204
}
214-
#endif
215205
}
216206

217207
// Shutdown the native library in a finalizer.
218208
private sealed class NativeShutdownObject : CriticalFinalizerObject
219209
{
220210
~NativeShutdownObject()
221211
{
222-
#if !NET46
223212
if (httpSubtransportRegistration != null)
224213
{
225214
GlobalSettings.UnregisterDefaultSmartSubtransport(httpSubtransportRegistration);
@@ -229,7 +218,6 @@ private sealed class NativeShutdownObject : CriticalFinalizerObject
229218
{
230219
GlobalSettings.UnregisterDefaultSmartSubtransport(httpsSubtransportRegistration);
231220
}
232-
#endif
233221

234222
git_libgit2_shutdown();
235223
}

LibGit2Sharp/Core/Platform.cs

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,11 @@ internal enum OperatingSystemType
1313
internal static class Platform
1414
{
1515
public static string ProcessorArchitecture => IntPtr.Size == 8 ? "x64" : "x86";
16-
#if NET46
17-
private static bool? _isRunningOnMac;
18-
private static bool IsRunningOnMac() => _isRunningOnMac ?? (_isRunningOnMac = TryGetIsRunningOnMac()) ?? false;
19-
#endif
2016

2117
public static OperatingSystemType OperatingSystem
2218
{
2319
get
2420
{
25-
#if NET46
26-
var platform = (int)Environment.OSVersion.Platform;
27-
if (platform <= 3 || platform == 5)
28-
{
29-
return OperatingSystemType.Windows;
30-
}
31-
if (IsRunningOnMac())
32-
{
33-
return OperatingSystemType.MacOSX;
34-
}
35-
if (platform == 4 || platform == 6 || platform == 128)
36-
{
37-
return OperatingSystemType.Unix;
38-
}
39-
#else
4021
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
4122
{
4223
return OperatingSystemType.Windows;
@@ -51,7 +32,7 @@ public static OperatingSystemType OperatingSystem
5132
{
5233
return OperatingSystemType.MacOSX;
5334
}
54-
#endif
35+
5536
throw new PlatformNotSupportedException();
5637
}
5738
}
@@ -90,70 +71,5 @@ public static bool IsRunningOnNetFramework()
9071
/// </summary>
9172
public static bool IsRunningOnNetCore()
9273
=> typeof(object).Assembly.GetName().Name != "mscorlib";
93-
94-
#if NET46
95-
#pragma warning disable IDE1006 // Naming Styles
96-
[DllImport("libc")]
97-
private static extern int sysctlbyname(
98-
[MarshalAs(UnmanagedType.LPStr)] string property,
99-
IntPtr output,
100-
IntPtr oldLen,
101-
IntPtr newp,
102-
uint newlen);
103-
#pragma warning restore IDE1006 // Naming Styles
104-
105-
private static bool TryGetIsRunningOnMac()
106-
{
107-
const string OsType = "kern.ostype";
108-
const string MacOsType = "Darwin";
109-
110-
return MacOsType == GetOsType();
111-
112-
string GetOsType()
113-
{
114-
try
115-
{
116-
IntPtr
117-
pointerLength = IntPtr.Zero,
118-
pointerString = IntPtr.Zero;
119-
120-
try
121-
{
122-
pointerLength = Marshal.AllocHGlobal(sizeof(int));
123-
124-
sysctlbyname(OsType, IntPtr.Zero, pointerLength, IntPtr.Zero, 0);
125-
126-
var length = Marshal.ReadInt32(pointerLength);
127-
128-
if (length <= 0)
129-
{
130-
return string.Empty;
131-
}
132-
133-
pointerString = Marshal.AllocHGlobal(length);
134-
135-
sysctlbyname(OsType, pointerString, pointerLength, IntPtr.Zero, 0);
136-
137-
return Marshal.PtrToStringAnsi(pointerString);
138-
}
139-
finally
140-
{
141-
if (pointerLength != IntPtr.Zero)
142-
{
143-
Marshal.FreeHGlobal(pointerLength);
144-
}
145-
if (pointerString != IntPtr.Zero)
146-
{
147-
Marshal.FreeHGlobal(pointerString);
148-
}
149-
}
150-
}
151-
catch
152-
{
153-
return null;
154-
}
155-
}
156-
}
157-
#endif
15874
}
15975
}

LibGit2Sharp/GlobalSettings.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ public static class GlobalSettings
2222
private static bool nativeLibraryPathLocked;
2323
private static string nativeLibraryDefaultPath;
2424

25-
#if !NET46
2625
private static bool useManagedHttpSmartSubtransport;
27-
#endif
2826

2927
internal class SmartSubtransportData
3028
{
@@ -85,9 +83,7 @@ private static string GetExecutingAssemblyDirectory()
8583
/// </summary>
8684
public static Version Version => version.Value;
8785

88-
#if !NET46
8986
internal static bool ManagedHttpSmartSubtransportEnabled => RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || useManagedHttpSmartSubtransport;
90-
#endif
9187

9288
private static SmartSubtransportData GetOrCreateSmartSubtransportData(string scheme)
9389
{
@@ -544,14 +540,12 @@ public static string GetUserAgent()
544540
return Proxy.git_libgit2_opts_get_user_agent();
545541
}
546542

547-
#if !NET46
548543
/// <summary>
549544
/// Enables the managed http implementation. This is enabled autmatically on Linux, so this method is only needed when running on Windows or macOS.
550545
/// </summary>
551546
public static void UseManagedHttpSmartSubtransport()
552547
{
553548
useManagedHttpSmartSubtransport = true;
554549
}
555-
#endif
556550
}
557551
}

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;net46;net472</TargetFrameworks>
4+
<TargetFramework>netstandard2.0</TargetFramework>
55
<GenerateDocumentationFile>true</GenerateDocumentationFile>
66
<Description>LibGit2Sharp brings all the might and speed of libgit2, a native Git implementation, to the managed world of .Net and Mono.</Description>
77
<Company>LibGit2Sharp contributors</Company>

NativeLibraryLoadTestApp/x64/NativeLibraryLoadTestApp.x64.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>net46;net472</TargetFrameworks>
5+
<TargetFramework>net472</TargetFramework>
66
<PlatformTarget>x64</PlatformTarget>
77
</PropertyGroup>
88

NativeLibraryLoadTestApp/x86/NativeLibraryLoadTestApp.x86.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>net46;net472</TargetFrameworks>
5+
<TargetFramework>net472</TargetFramework>
66
<PlatformTarget>x86</PlatformTarget>
77
</PropertyGroup>
88

0 commit comments

Comments
 (0)
0