Skip to content

Commit 069df60

Browse files
committed
dotnet: drop .NET Framework-specific code
1 parent 4766736 commit 069df60

File tree

9 files changed

+12
-92
lines changed

9 files changed

+12
-92
lines changed

src/shared/Core/Authentication/AuthenticationBase.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ protected internal virtual async Task<IDictionary<string, string>> InvokeHelperA
6060
// Write the standard input to the process if we have any to write
6161
if (standardInput is not null)
6262
{
63-
#if NETFRAMEWORK
64-
await standardInput.BaseStream.CopyToAsync(process.StandardInput.BaseStream);
65-
#else
6663
await standardInput.BaseStream.CopyToAsync(process.StandardInput.BaseStream, ct);
67-
#endif
6864
process.StandardInput.Close();
6965
}
7066

src/shared/Core/Authentication/MicrosoftAuthentication.cs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
using GitCredentialManager.UI.ViewModels;
1616
using GitCredentialManager.UI.Views;
1717
using Microsoft.Identity.Client.AppConfig;
18-
19-
#if NETFRAMEWORK
2018
using Microsoft.Identity.Client.Broker;
21-
#endif
2219

2320
namespace GitCredentialManager.Authentication
2421
{
@@ -508,15 +505,13 @@ private async Task<IPublicClientApplication> CreatePublicClientApplicationAsync(
508505
// to save on the distribution size of the .NET builds (no need for MSALRuntime bits).
509506
if (enableBroker)
510507
{
511-
#if NETFRAMEWORK
512508
appBuilder.WithBroker(
513509
new BrokerOptions(BrokerOptions.OperatingSystems.Windows)
514510
{
515511
Title = "Git Credential Manager",
516512
MsaPassthrough = msaPt,
517513
}
518514
);
519-
#endif
520515
}
521516

522517
IPublicClientApplication app = appBuilder.Build();
@@ -808,7 +803,6 @@ public HttpClient GetHttpClient()
808803

809804
public bool CanUseBroker()
810805
{
811-
#if NETFRAMEWORK
812806
// We only support the broker on Windows 10+ and in an interactive session
813807
if (!Context.SessionManager.IsDesktopSession || !PlatformUtils.IsWindowsBrokerSupported())
814808
{
@@ -827,34 +821,27 @@ public bool CanUseBroker()
827821
}
828822

829823
return defaultValue;
830-
#else
831-
// OS broker requires .NET Framework right now until we migrate to .NET 5.0 (net5.0-windows10.x.y.z)
832-
return false;
833-
#endif
834824
}
835825

836826
private bool CanUseEmbeddedWebView()
837827
{
838-
// If we're in an interactive session and on .NET Framework then MSAL can show the WinForms-based embedded UI
839-
#if NETFRAMEWORK
840-
return Context.SessionManager.IsDesktopSession;
841-
#else
842-
return false;
843-
#endif
828+
// If we're in an interactive session and on Windows then MSAL can show the WinForms-based embedded UI
829+
return PlatformUtils.IsWindows() && Context.SessionManager.IsDesktopSession;
844830
}
845831

846832
private void EnsureCanUseEmbeddedWebView()
847833
{
848-
#if NETFRAMEWORK
849834
if (!Context.SessionManager.IsDesktopSession)
850835
{
851836
throw new Trace2InvalidOperationException(Context.Trace2,
852837
"Embedded web view is not available without a desktop session.");
853838
}
854-
#else
855-
throw new Trace2InvalidOperationException(Context.Trace2,
856-
"Embedded web view is not available on .NET Core.");
857-
#endif
839+
840+
if (!PlatformUtils.IsWindows())
841+
{
842+
throw new Trace2InvalidOperationException(Context.Trace2,
843+
"Embedded web view is only available on Windows.");
844+
}
858845
}
859846

860847
private bool CanUseSystemWebView(IPublicClientApplication app, Uri redirectUri)

src/shared/Core/CurlCookie.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,12 @@ public IList<Cookie> Parse(string content)
6666

6767
private static DateTime ParseExpires(string expires)
6868
{
69-
#if NETFRAMEWORK
70-
DateTime epoch = new DateTime(1970, 01, 01, 0, 0, 0, DateTimeKind.Utc);
71-
#else
72-
DateTime epoch = DateTime.UnixEpoch;
73-
#endif
74-
7569
if (long.TryParse(expires, out long i))
7670
{
77-
return epoch.AddSeconds(i);
71+
return DateTime.UnixEpoch.AddSeconds(i);
7872
}
7973

80-
return epoch;
74+
return DateTime.UnixEpoch;
8175
}
8276
}
83-
}
77+
}

src/shared/Core/HttpClientFactory.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,7 @@ public HttpClient CreateClient()
9999
_streams.Error.WriteLine("warning: ---------------------------------------------------");
100100
_streams.Error.WriteLine($"warning: HTTPS connections may not be secure. See {Constants.HelpUrls.GcmTlsVerification} for more information.");
101101

102-
#if NETFRAMEWORK
103-
ServicePointManager.ServerCertificateValidationCallback = (req, cert, chain, errors) => true;
104-
#else
105102
handler.ServerCertificateCustomValidationCallback = (req, cert, chain, errors) => true;
106-
#endif
107103
}
108104
// If schannel is the TLS backend, custom certificate usage must be explicitly enabled
109105
else if (!string.IsNullOrWhiteSpace(_settings.CustomCertificateBundlePath) &&
@@ -178,23 +174,7 @@ public HttpClient CreateClient()
178174

179175
// Set the custom server certificate validation callback.
180176
// NOTE: this is executed after the default platform server certificate validation is performed
181-
#if NETFRAMEWORK
182-
ServicePointManager.ServerCertificateValidationCallback = (_, cert, chain, errors) =>
183-
{
184-
// Fail immediately if the cert or chain isn't present
185-
if (cert is null || chain is null)
186-
{
187-
return false;
188-
}
189-
190-
using (X509Certificate2 cert2 = new X509Certificate2(cert))
191-
{
192-
return validationCallback(cert2, chain, errors);
193-
}
194-
};
195-
#else
196177
handler.ServerCertificateCustomValidationCallback = (_, cert, chain, errors) => validationCallback(cert, chain, errors);
197-
#endif
198178
}
199179

200180
// If CustomCookieFilePath is set, set Cookie header from cookie file, which is written by libcurl

src/shared/Core/Interop/Posix/PosixFileSystem.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ public abstract class PosixFileSystem : FileSystem
1313
/// <exception cref="ArgumentException">Path is not absolute.</exception>
1414
protected internal static string ResolveSymbolicLinks(string path)
1515
{
16-
#if NETFRAMEWORK
17-
// Support for symlinks only exists in .NET 6+.
18-
// Since we're still targeting .NET Framework on Windows it
19-
// doesn't matter if we don't resolve symlinks for POSIX here
20-
// (unless we're running on Mono.. but why do that?)
21-
return path;
22-
#else
2316
if (!Path.IsPathRooted(path))
2417
{
2518
throw new ArgumentException("Path must be absolute", nameof(path));
@@ -54,10 +47,8 @@ protected internal static string ResolveSymbolicLinks(string path)
5447
}
5548

5649
return Path.Combine("/", partialPath);
57-
#endif
5850
}
5951

60-
#if !NETFRAMEWORK
6152
private static bool TryResolveFileLink(string path, out string target)
6253
{
6354
FileSystemInfo fsi = File.ResolveLinkTarget(path, true);
@@ -71,6 +62,5 @@ private static bool TryResolveDirectoryLink(string path, out string target)
7162
target = fsi?.FullName;
7263
return fsi != null;
7364
}
74-
#endif
7565
}
7666
}

src/shared/Core/Interop/Windows/WindowsSettings.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ protected override bool TryGetExternalDefault(string section, string scope, stri
2121
{
2222
value = null;
2323

24-
#if NETFRAMEWORK
2524
// Check for machine (HKLM) registry keys that match the Git configuration name.
2625
// These can be set by system administrators via Group Policy, so make useful defaults.
2726
using (Microsoft.Win32.RegistryKey configKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(Constants.WindowsRegistry.HKConfigurationPath))
@@ -48,9 +47,6 @@ protected override bool TryGetExternalDefault(string section, string scope, stri
4847

4948
return true;
5049
}
51-
#else
52-
return base.TryGetExternalDefault(section, scope, property, out value);
53-
#endif
5450
}
5551
}
5652
}

src/shared/Core/PlatformUtils.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public static bool IsDevBox()
3131
return false;
3232
}
3333

34-
#if NETFRAMEWORK
3534
// Check for machine (HKLM) registry keys for Cloud PC indicators
3635
// Note that the keys are only found in the 64-bit registry view
3736
using (Microsoft.Win32.RegistryKey hklm64 = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64))
@@ -48,9 +47,6 @@ public static bool IsDevBox()
4847

4948
return w365Value is not null && Guid.TryParse(partnerValue, out Guid partnerId) && partnerId == Constants.DevBoxPartnerId;
5049
}
51-
#else
52-
return false;
53-
#endif
5450
}
5551

5652
/// <summary>
@@ -197,11 +193,9 @@ public static bool IsElevatedUser()
197193
{
198194
if (IsWindows())
199195
{
200-
#if NETFRAMEWORK
201196
var identity = System.Security.Principal.WindowsIdentity.GetCurrent();
202197
var principal = new System.Security.Principal.WindowsPrincipal(identity);
203198
return principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator);
204-
#endif
205199
}
206200
else if (IsPosix())
207201
{
@@ -287,9 +281,6 @@ private static string GetLinuxEntryPath()
287281
}
288282
}
289283

290-
#if NETFRAMEWORK
291-
return null;
292-
#else
293284
//
294285
// We cannot determine the absolute file path from argv[0]
295286
// (how we were launched), so let's now try to extract the
@@ -299,7 +290,6 @@ private static string GetLinuxEntryPath()
299290
//
300291
FileSystemInfo fsi = File.ResolveLinkTarget("/proc/self/exe", returnFinalTarget: false);
301292
return fsi?.FullName;
302-
#endif
303293
}
304294

305295
private static string GetMacOSEntryPath()
@@ -368,12 +358,11 @@ private static string GetOSVersion(ITrace2 trace2)
368358
// However, we still need to use the old method for Windows on .NET Framework
369359
// and call into the Win32 API to get the correct version (regardless of app
370360
// compatibility settings).
371-
#if NETFRAMEWORK
372361
if (IsWindows() && RtlGetVersionEx(out RTL_OSVERSIONINFOEX osvi) == 0)
373362
{
374363
return $"{osvi.dwMajorVersion}.{osvi.dwMinorVersion} (build {osvi.dwBuildNumber})";
375364
}
376-
#endif
365+
377366
if (IsWindows() || IsMacOS())
378367
{
379368
return Environment.OSVersion.Version.ToString();

src/shared/Core/UI/AvaloniaUi.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,15 @@ public static Task ShowWindowAsync(Func<Window> windowFunc, object dataContext,
6565
{
6666
var appBuilder = AppBuilder.Configure<AvaloniaApp>();
6767

68-
#if NETFRAMEWORK
6968
// Set custom rendering options and modes if required
7069
if (PlatformUtils.IsWindows() && _win32SoftwareRendering)
7170
{
7271
appBuilder.With(new Win32PlatformOptions
7372
{ RenderingMode = new[] { Win32RenderingMode.Software } });
7473
}
75-
#endif
7674

7775
appBuilder
78-
#if NETFRAMEWORK
79-
.UseWin32()
80-
.UseSkia()
81-
#else
8276
.UsePlatformDetect()
83-
#endif
8477
.LogToTrace()
8578
.SetupWithoutStarting();
8679

src/shared/Git-Credential-Manager/Program.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,7 @@ private static void AppMain(object o)
7676
// Required for Avalonia designer
7777
static AppBuilder BuildAvaloniaApp() =>
7878
AppBuilder.Configure<AvaloniaApp>()
79-
#if NETFRAMEWORK
80-
.UseWin32()
81-
.UseSkia()
82-
#else
8379
.UsePlatformDetect()
84-
#endif
8580
.LogToTrace();
8681
}
8782
}

0 commit comments

Comments
 (0)