Skip to content

Commit 26735d1

Browse files
committed
dotnet: drop .NET Framework-specific code
1 parent 09f6421 commit 26735d1

File tree

9 files changed

+12
-110
lines changed

9 files changed

+12
-110
lines changed

src/shared/Core/Authentication/AuthenticationBase.cs

-4
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

+8-21
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
{
@@ -501,15 +498,13 @@ private async Task<IPublicClientApplication> CreatePublicClientApplicationAsync(
501498
// to save on the distribution size of the .NET builds (no need for MSALRuntime bits).
502499
if (enableBroker)
503500
{
504-
#if NETFRAMEWORK
505501
appBuilder.WithBroker(
506502
new BrokerOptions(BrokerOptions.OperatingSystems.Windows)
507503
{
508504
Title = "Git Credential Manager",
509505
MsaPassthrough = msaPt,
510506
}
511507
);
512-
#endif
513508
}
514509

515510
IPublicClientApplication app = appBuilder.Build();
@@ -801,7 +796,6 @@ public HttpClient GetHttpClient()
801796

802797
public bool CanUseBroker()
803798
{
804-
#if NETFRAMEWORK
805799
// We only support the broker on Windows 10+ and in an interactive session
806800
if (!Context.SessionManager.IsDesktopSession || !PlatformUtils.IsWindowsBrokerSupported())
807801
{
@@ -820,34 +814,27 @@ public bool CanUseBroker()
820814
}
821815

822816
return defaultValue;
823-
#else
824-
// OS broker requires .NET Framework right now until we migrate to .NET 5.0 (net5.0-windows10.x.y.z)
825-
return false;
826-
#endif
827817
}
828818

829819
private bool CanUseEmbeddedWebView()
830820
{
831-
// If we're in an interactive session and on .NET Framework then MSAL can show the WinForms-based embedded UI
832-
#if NETFRAMEWORK
833-
return Context.SessionManager.IsDesktopSession;
834-
#else
835-
return false;
836-
#endif
821+
// If we're in an interactive session and on Windows then MSAL can show the WinForms-based embedded UI
822+
return PlatformUtils.IsWindows() && Context.SessionManager.IsDesktopSession;
837823
}
838824

839825
private void EnsureCanUseEmbeddedWebView()
840826
{
841-
#if NETFRAMEWORK
842827
if (!Context.SessionManager.IsDesktopSession)
843828
{
844829
throw new Trace2InvalidOperationException(Context.Trace2,
845830
"Embedded web view is not available without a desktop session.");
846831
}
847-
#else
848-
throw new Trace2InvalidOperationException(Context.Trace2,
849-
"Embedded web view is not available on .NET Core.");
850-
#endif
832+
833+
if (!PlatformUtils.IsWindows())
834+
{
835+
throw new Trace2InvalidOperationException(Context.Trace2,
836+
"Embedded web view is only available on Windows.");
837+
}
851838
}
852839

853840
private bool CanUseSystemWebView(IPublicClientApplication app, Uri redirectUri)

src/shared/Core/CurlCookie.cs

+3-9
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

-20
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

-10
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

-4
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

+1-32
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
public static bool IsWindowsBrokerSupported()
@@ -99,11 +95,7 @@ public static bool IsWindowsBrokerSupported()
9995
/// <returns>True if running on macOS, false otherwise.</returns>
10096
public static bool IsMacOS()
10197
{
102-
#if NETFRAMEWORK
103-
return Environment.OSVersion.Platform == PlatformID.MacOSX;
104-
#else
10598
return RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
106-
#endif
10799
}
108100

109101
/// <summary>
@@ -112,11 +104,7 @@ public static bool IsMacOS()
112104
/// <returns>True if running on Windows, false otherwise.</returns>
113105
public static bool IsWindows()
114106
{
115-
#if NETFRAMEWORK
116-
return Environment.OSVersion.Platform == PlatformID.Win32NT;
117-
#else
118107
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
119-
#endif
120108
}
121109

122110
/// <summary>
@@ -125,11 +113,7 @@ public static bool IsWindows()
125113
/// <returns>True if running on a Linux distribution, false otherwise.</returns>
126114
public static bool IsLinux()
127115
{
128-
#if NETFRAMEWORK
129-
return Environment.OSVersion.Platform == PlatformID.Unix;
130-
#else
131116
return RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
132-
#endif
133117
}
134118

135119
/// <summary>
@@ -193,11 +177,9 @@ public static bool IsElevatedUser()
193177
{
194178
if (IsWindows())
195179
{
196-
#if NETFRAMEWORK
197180
var identity = System.Security.Principal.WindowsIdentity.GetCurrent();
198181
var principal = new System.Security.Principal.WindowsPrincipal(identity);
199182
return principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator);
200-
#endif
201183
}
202184
else if (IsPosix())
203185
{
@@ -283,9 +265,6 @@ private static string GetLinuxEntryPath()
283265
}
284266
}
285267

286-
#if NETFRAMEWORK
287-
return null;
288-
#else
289268
//
290269
// We cannot determine the absolute file path from argv[0]
291270
// (how we were launched), so let's now try to extract the
@@ -295,7 +274,6 @@ private static string GetLinuxEntryPath()
295274
//
296275
FileSystemInfo fsi = File.ResolveLinkTarget("/proc/self/exe", returnFinalTarget: false);
297276
return fsi?.FullName;
298-
#endif
299277
}
300278

301279
private static string GetMacOSEntryPath()
@@ -364,12 +342,11 @@ private static string GetOSVersion(ITrace2 trace2)
364342
// However, we still need to use the old method for Windows on .NET Framework
365343
// and call into the Win32 API to get the correct version (regardless of app
366344
// compatibility settings).
367-
#if NETFRAMEWORK
368345
if (IsWindows() && RtlGetVersionEx(out RTL_OSVERSIONINFOEX osvi) == 0)
369346
{
370347
return $"{osvi.dwMajorVersion}.{osvi.dwMinorVersion} (build {osvi.dwBuildNumber})";
371348
}
372-
#endif
349+
373350
if (IsWindows() || IsMacOS())
374351
{
375352
return Environment.OSVersion.Version.ToString();
@@ -459,9 +436,6 @@ string GetLinuxDistroVersion()
459436

460437
private static string GetCpuArchitecture()
461438
{
462-
#if NETFRAMEWORK
463-
return Environment.Is64BitOperatingSystem ? "x86-64" : "x86";
464-
#else
465439
switch (RuntimeInformation.OSArchitecture)
466440
{
467441
case Architecture.Arm:
@@ -475,16 +449,11 @@ private static string GetCpuArchitecture()
475449
default:
476450
return RuntimeInformation.OSArchitecture.ToString();
477451
}
478-
#endif
479452
}
480453

481454
private static string GetClrVersion()
482455
{
483-
#if NETFRAMEWORK
484-
return $".NET Framework {Environment.Version}";
485-
#else
486456
return RuntimeInformation.FrameworkDescription;
487-
#endif
488457
}
489458

490459
#endregion

src/shared/Core/UI/AvaloniaUi.cs

-5
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,7 @@ public static Task ShowWindowAsync(Func<Window> windowFunc, object dataContext,
4747
Dispatcher.MainThread.Post(appCancelToken =>
4848
{
4949
AppBuilder.Configure<AvaloniaApp>()
50-
#if NETFRAMEWORK
51-
.UseWin32()
52-
.UseSkia()
53-
#else
5450
.UsePlatformDetect()
55-
#endif
5651
.LogToTrace()
5752
// Workaround https://github.com/AvaloniaUI/Avalonia/issues/10296
5853
// by always setting a application lifetime.

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

-5
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)