Skip to content

Commit 27a034d

Browse files
committed
Only use managed https with new net472 target
1 parent f5abbba commit 27a034d

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

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

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

77
<ItemGroup>
@@ -23,7 +23,7 @@
2323

2424
<ItemGroup>
2525
<Compile Include="..\LibGit2Sharp\Core\Platform.cs" Link="TestHelpers\Platform.cs" />
26-
<Compile Remove="desktop\**" Condition="'$(TargetFramework)' != 'net46'" />
26+
<Compile Remove="desktop\**" Condition="'$(TargetFramework)' == 'netcoreapp2.1'" />
2727
<Content Include="Resources\**\*.*" CopyToOutputDirectory="PreserveNewest" />
2828
<None Update="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
2929
</ItemGroup>

LibGit2Sharp/Core/ManagedHttpSmartSubtransport.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if !NET46
12
using System;
23
using System.IO;
34
using System.Linq;
@@ -277,3 +278,4 @@ protected override void Free()
277278
}
278279
}
279280
}
281+
#endif

LibGit2Sharp/Core/NativeMethods.cs

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

29+
#if !NET46
2930
private static SmartSubtransportRegistration<ManagedHttpSmartSubtransport> httpSubtransportRegistration;
3031
private static SmartSubtransportRegistration<ManagedHttpSmartSubtransport> httpsSubtransportRegistration;
32+
#endif
3133

3234
static NativeMethods()
3335
{
@@ -45,7 +47,7 @@ static NativeMethods()
4547
string nativeLibraryPath = GetGlobalSettingsNativeLibraryPath();
4648
if (nativeLibraryPath != null)
4749
{
48-
#if NETFRAMEWORK
50+
#if NET46
4951
if (Platform.OperatingSystem == OperatingSystemType.Windows)
5052
#else
5153
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
@@ -202,19 +204,22 @@ private static void InitializeNativeLibrary()
202204
shutdownObject = new NativeShutdownObject();
203205
}
204206

207+
#if !NET46
205208
// Configure the .NET HTTP(S) mechanism on the first initialization of the library in the current process.
206209
if (initCounter == 1)
207210
{
208211
httpSubtransportRegistration = GlobalSettings.RegisterDefaultSmartSubtransport<ManagedHttpSmartSubtransport>("http");
209212
httpsSubtransportRegistration = GlobalSettings.RegisterDefaultSmartSubtransport<ManagedHttpSmartSubtransport>("https");
210213
}
214+
#endif
211215
}
212216

213217
// Shutdown the native library in a finalizer.
214218
private sealed class NativeShutdownObject : CriticalFinalizerObject
215219
{
216220
~NativeShutdownObject()
217221
{
222+
#if !NET46
218223
if (httpSubtransportRegistration != null)
219224
{
220225
GlobalSettings.UnregisterDefaultSmartSubtransport(httpSubtransportRegistration);
@@ -224,6 +229,7 @@ private sealed class NativeShutdownObject : CriticalFinalizerObject
224229
{
225230
GlobalSettings.UnregisterDefaultSmartSubtransport(httpsSubtransportRegistration);
226231
}
232+
#endif
227233

228234
git_libgit2_shutdown();
229235
}

LibGit2Sharp/Core/Platform.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal enum OperatingSystemType
1313
internal static class Platform
1414
{
1515
public static string ProcessorArchitecture => IntPtr.Size == 8 ? "x64" : "x86";
16-
#if NETFRAMEWORK
16+
#if NET46
1717
private static bool? _isRunningOnMac;
1818
private static bool IsRunningOnMac() => _isRunningOnMac ?? (_isRunningOnMac = TryGetIsRunningOnMac()) ?? false;
1919
#endif
@@ -22,7 +22,7 @@ public static OperatingSystemType OperatingSystem
2222
{
2323
get
2424
{
25-
#if NETFRAMEWORK
25+
#if NET46
2626
var platform = (int)Environment.OSVersion.Platform;
2727
if (platform <= 3 || platform == 5)
2828
{
@@ -91,7 +91,7 @@ public static bool IsRunningOnNetFramework()
9191
public static bool IsRunningOnNetCore()
9292
=> typeof(object).Assembly.GetName().Name != "mscorlib";
9393

94-
#if NETFRAMEWORK
94+
#if NET46
9595
#pragma warning disable IDE1006 // Naming Styles
9696
[DllImport("libc")]
9797
private static extern int sysctlbyname(

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 5 additions & 2 deletions
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</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;net46;net472</TargetFrameworks>
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>
@@ -31,11 +31,14 @@
3131
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" /> <!-- Needed for T4 generation -->
3232
</ItemGroup>
3333

34+
<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
35+
<Reference Include="System.Net.Http" />
36+
</ItemGroup>
37+
3438
<ItemGroup>
3539
<PackageReference Include="LibGit2Sharp.NativeBinaries" Version="[2.0.305]" PrivateAssets="none" />
3640
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="all" />
3741
<PackageReference Include="Nerdbank.GitVersioning" Version="3.0.50" PrivateAssets="all" />
38-
<PackageReference Include="System.Net.Http" Version="4.3.4" />
3942
</ItemGroup>
4043

4144
<Import Project="..\Targets\CodeGenerator.targets" />

0 commit comments

Comments
 (0)