diff --git a/build/Shared/DeconstructionExtensions.cs b/build/Shared/DeconstructionExtensions.cs deleted file mode 100644 index 0666ea5a46f..00000000000 --- a/build/Shared/DeconstructionExtensions.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information. - -#if NETFRAMEWORK || NETSTANDARD2_0 - -using System.Diagnostics; - -namespace System.Collections.Generic; - -internal static class DeconstructionExtensions -{ - [DebuggerStepThrough] - public static void Deconstruct(this KeyValuePair pair, out TKey key, out TValue value) - { - key = pair.Key; - value = pair.Value; - } -} - -#endif diff --git a/build/Shared/NullableAttributes.cs b/build/Shared/NullableAttributes.cs index 6b9f9d19dbf..d2ea0000a17 100644 --- a/build/Shared/NullableAttributes.cs +++ b/build/Shared/NullableAttributes.cs @@ -4,11 +4,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#if !NETSTANDARD2_1 && !NETCOREAPP3_1_OR_GREATER && !NET5_0_OR_GREATER +#if NETFRAMEWORK namespace System.Diagnostics.CodeAnalysis { -#if !NETSTANDARD2_1 /// Specifies that null is allowed as an input even if the corresponding type disallows it. [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] #if SYSTEM_PRIVATE_CORELIB @@ -135,7 +134,6 @@ sealed class DoesNotReturnIfAttribute : Attribute /// Gets the condition parameter value. public bool ParameterValue { get; } } -#endif /// Specifies that the method or property will ensure that the listed field and property members have not-null values. [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] diff --git a/src/NuGet.Core/Microsoft.Build.NuGetSdkResolver/FileSystemInfoFullNameEqualityComparer.cs b/src/NuGet.Core/Microsoft.Build.NuGetSdkResolver/FileSystemInfoFullNameEqualityComparer.cs index a1837ab01ab..22f5908d2aa 100644 --- a/src/NuGet.Core/Microsoft.Build.NuGetSdkResolver/FileSystemInfoFullNameEqualityComparer.cs +++ b/src/NuGet.Core/Microsoft.Build.NuGetSdkResolver/FileSystemInfoFullNameEqualityComparer.cs @@ -44,7 +44,7 @@ public bool Equals(FileSystemInfo x, FileSystemInfo y) /// A hash code for the specified object's property.. public int GetHashCode(FileSystemInfo obj) { -#if NETFRAMEWORK || NETSTANDARD +#if NETFRAMEWORK return obj.FullName.GetHashCode(); #else return obj.FullName.GetHashCode(StringComparison.Ordinal); diff --git a/src/NuGet.Core/NuGet.Build.Tasks/GetReferenceNearestTargetFrameworkTask.cs b/src/NuGet.Core/NuGet.Build.Tasks/GetReferenceNearestTargetFrameworkTask.cs index d577b03a212..f74fc685e57 100644 --- a/src/NuGet.Core/NuGet.Build.Tasks/GetReferenceNearestTargetFrameworkTask.cs +++ b/src/NuGet.Core/NuGet.Build.Tasks/GetReferenceNearestTargetFrameworkTask.cs @@ -213,7 +213,7 @@ private static bool TryParseFramework(string framework, string errorMessage, MSB private static bool TryParseFramework(string targetFrameworkMoniker, string targetPlatformMoniker, string errorMessage, MSBuildLogger logger, out NuGetFramework nugetFramework) { // Check if we have a long name. -#if NETFRAMEWORK || NETSTANDARD +#if NETFRAMEWORK nugetFramework = targetFrameworkMoniker.Contains(',') ? NuGetFramework.ParseComponents(targetFrameworkMoniker, targetPlatformMoniker) : NuGetFramework.Parse(targetFrameworkMoniker); diff --git a/src/NuGet.Core/NuGet.Commands/Internal/HashCodeCombiner.cs b/src/NuGet.Core/NuGet.Commands/Internal/HashCodeCombiner.cs index 15badf1abb7..0913a43d755 100644 --- a/src/NuGet.Core/NuGet.Commands/Internal/HashCodeCombiner.cs +++ b/src/NuGet.Core/NuGet.Commands/Internal/HashCodeCombiner.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; -#if !NETFRAMEWORK && !NETSTANDARD +#if NET using System; #endif @@ -61,7 +61,7 @@ public void Add(int i) [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(string s) { -#if NETFRAMEWORK || NETSTANDARD +#if NETFRAMEWORK var hashCode = (s != null) ? s.GetHashCode() : 0; #else var hashCode = (s != null) ? s.GetHashCode(StringComparison.Ordinal) : 0; diff --git a/src/NuGet.Core/NuGet.DependencyResolver.Core/GraphModel/Tracker.cs b/src/NuGet.Core/NuGet.DependencyResolver.Core/GraphModel/Tracker.cs index 613b4908626..239c433e4fc 100644 --- a/src/NuGet.Core/NuGet.DependencyResolver.Core/GraphModel/Tracker.cs +++ b/src/NuGet.Core/NuGet.DependencyResolver.Core/GraphModel/Tracker.cs @@ -115,11 +115,7 @@ public void AddItem(GraphItem item) { if (!existingItem.Equals(item)) { -#if NETSTANDARD2_0 - _storage = new HashSet>() { existingItem, item }; -#else _storage = new HashSet>(capacity: 3) { existingItem, item }; -#endif } } else diff --git a/src/NuGet.Core/NuGet.Packaging/ContentModel/ContentItemCollection.cs b/src/NuGet.Core/NuGet.Packaging/ContentModel/ContentItemCollection.cs index 8b18ec3e768..59c51d8a7ff 100644 --- a/src/NuGet.Core/NuGet.Packaging/ContentModel/ContentItemCollection.cs +++ b/src/NuGet.Core/NuGet.Packaging/ContentModel/ContentItemCollection.cs @@ -378,7 +378,7 @@ public int GetHashCode(ContentItem obj) { foreach (var property in obj._properties) { -#if NETFRAMEWORK || NETSTANDARD +#if NETFRAMEWORK hashCode ^= property.Key.GetHashCode(); #else hashCode ^= property.Key.GetHashCode(StringComparison.Ordinal); diff --git a/src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/PhysicalPackageFile.cs b/src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/PhysicalPackageFile.cs index 41a8b9ed62e..ad0c90b3071 100644 --- a/src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/PhysicalPackageFile.cs +++ b/src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/PhysicalPackageFile.cs @@ -117,7 +117,7 @@ public override int GetHashCode() int hash = 0; if (SourcePath != null) { -#if NETFRAMEWORK || NETSTANDARD +#if NETFRAMEWORK hash = SourcePath.GetHashCode(); #else hash = SourcePath.GetHashCode(StringComparison.Ordinal); @@ -126,7 +126,7 @@ public override int GetHashCode() if (TargetPath != null) { -#if NETFRAMEWORK || NETSTANDARD +#if NETFRAMEWORK hash = hash * 4567 + TargetPath.GetHashCode(); #else hash = hash * 4567 + TargetPath.GetHashCode(StringComparison.Ordinal); diff --git a/src/NuGet.Core/NuGet.Packaging/PackageExtraction/StreamExtensions.cs b/src/NuGet.Core/NuGet.Packaging/PackageExtraction/StreamExtensions.cs index 574953fdb04..2ff3164db68 100644 --- a/src/NuGet.Core/NuGet.Packaging/PackageExtraction/StreamExtensions.cs +++ b/src/NuGet.Core/NuGet.Packaging/PackageExtraction/StreamExtensions.cs @@ -6,10 +6,6 @@ using System.IO.MemoryMappedFiles; using NuGet.Common; -#if NETFRAMEWORK || NETSTANDARD2_0 -using System.Buffers; -#endif - namespace NuGet.Packaging { public static class StreamExtensions @@ -19,28 +15,6 @@ public static string CopyToFile(this Stream inputStream, string fileFullPath) return Testable.Default.CopyToFile(inputStream, fileFullPath); } - private static void CopyTo(Stream inputStream, Stream outputStream) - { - // .NET Framework allocates an unavoidable byte[] when using - // Stream.CopyTo. Reimplement it, pulling from the pool similar - // to .NET 5. - -#if NETFRAMEWORK || NETSTANDARD2_0 - const int bufferSize = 81920; // Same as Stream.CopyTo - byte[] buffer = ArrayPool.Shared.Rent(bufferSize); - - int bytesRead; - while ((bytesRead = inputStream.Read(buffer, offset: 0, buffer.Length)) != 0) - { - outputStream.Write(buffer, offset: 0, bytesRead); - } - - ArrayPool.Shared.Return(buffer); -#else - inputStream.CopyTo(outputStream); -#endif - } - internal class Testable { // Only files smaller than this value will be mmap'ed @@ -127,7 +101,7 @@ internal virtual void MmapCopy(Stream inputStream, string fileFullPath, long siz using (MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(fileFullPath, FileMode.Open, mapName: null, size)) using (MemoryMappedViewStream mmstream = mmf.CreateViewStream()) { - CopyTo(inputStream, mmstream); + inputStream.CopyTo(mmstream); } } } @@ -136,7 +110,7 @@ internal virtual void FileStreamCopy(Stream inputStream, string fileFullPath) { using (var outputStream = NuGetExtractionFileIO.CreateFile(fileFullPath)) { - CopyTo(inputStream, outputStream); + inputStream.CopyTo(outputStream); } } } diff --git a/src/NuGet.Core/NuGet.Packaging/RuntimeModel/RuntimeGraph.cs b/src/NuGet.Core/NuGet.Packaging/RuntimeModel/RuntimeGraph.cs index 36715ca4901..9938388c12f 100644 --- a/src/NuGet.Core/NuGet.Packaging/RuntimeModel/RuntimeGraph.cs +++ b/src/NuGet.Core/NuGet.Packaging/RuntimeModel/RuntimeGraph.cs @@ -267,13 +267,7 @@ public IEnumerable FindRuntimeDependencies(string runt if (_packagesWithDependencies.Contains(packageId)) { var key = new RuntimeDependencyKey(runtimeName, packageId); - -#if NET472_OR_GREATER || NET5_0_OR_GREATER - return _dependencyCache!.GetOrAdd(key, FindRuntimeDependenciesInternal, this); -#else - return _dependencyCache!.GetOrAdd(key, key => FindRuntimeDependenciesInternal(key, this)); -#endif } return Enumerable.Empty(); diff --git a/src/NuGet.Core/NuGet.ProjectModel/NoAllocNewLineStreamWriter.cs b/src/NuGet.Core/NuGet.ProjectModel/NoAllocNewLineStreamWriter.cs index 0c90ee7fc91..d8a4c1d65d8 100644 --- a/src/NuGet.Core/NuGet.ProjectModel/NoAllocNewLineStreamWriter.cs +++ b/src/NuGet.Core/NuGet.ProjectModel/NoAllocNewLineStreamWriter.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if NETFRAMEWORK || NETSTANDARD2_0_OR_GREATER +#if NETFRAMEWORK using System; using System.Diagnostics.CodeAnalysis; using System.IO; diff --git a/src/NuGet.Core/NuGet.ProjectModel/ProjectRestoreMetadata.cs b/src/NuGet.Core/NuGet.ProjectModel/ProjectRestoreMetadata.cs index f7d282b9a6f..afb611f31a4 100644 --- a/src/NuGet.Core/NuGet.ProjectModel/ProjectRestoreMetadata.cs +++ b/src/NuGet.Core/NuGet.ProjectModel/ProjectRestoreMetadata.cs @@ -243,11 +243,7 @@ public bool Equals(ProjectRestoreMetadata other) private HashSet GetSources(IList sources) { -#if NETSTANDARD2_0 - var setSources = new HashSet(StringComparer.OrdinalIgnoreCase); -#else var setSources = new HashSet(sources.Count, StringComparer.OrdinalIgnoreCase); -#endif for (var i = 0; i < sources.Count; i++) { setSources.Add(sources[i].Source); diff --git a/src/NuGet.Core/NuGet.Protocol/HttpSource/HttpHandlerResourceV3Provider.cs b/src/NuGet.Core/NuGet.Protocol/HttpSource/HttpHandlerResourceV3Provider.cs index f6b2102e7d9..15cde60c353 100644 --- a/src/NuGet.Core/NuGet.Protocol/HttpSource/HttpHandlerResourceV3Provider.cs +++ b/src/NuGet.Core/NuGet.Protocol/HttpSource/HttpHandlerResourceV3Provider.cs @@ -11,22 +11,12 @@ using NuGet.Configuration; using NuGet.Protocol.Core.Types; -#if NETSTANDARD2_0 -using System.Net.Security; -using System.Security.Cryptography.X509Certificates; -#endif - namespace NuGet.Protocol { public class HttpHandlerResourceV3Provider : ResourceProvider { private readonly IProxyCache _proxyCache; -#if NETSTANDARD2_0 - internal static Func DangerousAcceptAnyServerCertificateValidator = - (message, certificate, chain, policyErrors) => true; -#endif - public HttpHandlerResourceV3Provider() : this(ProxyCache.Instance) { @@ -66,17 +56,10 @@ private HttpHandlerResourceV3 CreateResource(PackageSource packageSource) AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate), }; -#if NETSTANDARD2_0 - if (packageSource.DisableTLSCertificateValidation) - { - clientHandler.ServerCertificateCustomValidationCallback = DangerousAcceptAnyServerCertificateValidator; - } -#else if (packageSource.DisableTLSCertificateValidation) { clientHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; } -#endif #if IS_DESKTOP if (packageSource.MaxHttpRequestsPerSource > 0) diff --git a/src/NuGet.Core/NuGet.Protocol/RemoteRepositories/HttpFileSystemBasedFindPackageByIdResource.cs b/src/NuGet.Core/NuGet.Protocol/RemoteRepositories/HttpFileSystemBasedFindPackageByIdResource.cs index aa681cdc5c8..f35c1b0a50e 100644 --- a/src/NuGet.Core/NuGet.Protocol/RemoteRepositories/HttpFileSystemBasedFindPackageByIdResource.cs +++ b/src/NuGet.Core/NuGet.Protocol/RemoteRepositories/HttpFileSystemBasedFindPackageByIdResource.cs @@ -432,23 +432,12 @@ private static bool TryGetVersionString(NuGetVersion version, HashSet.TryGetValue. The API docs say the version should be lowercase, but if - // a server doesn't follow the spec and uses case sensitive URLs, this might result in 404 responses. - if (!packageVersions.Contains(version)) - { - versionString = null; - return false; - } - versionString = version.ToNormalizedString().ToLowerInvariant(); -#endif return true; } @@ -582,12 +571,7 @@ private static async Task> ConsumeFlatContainerIndexAsync( { var json = await JsonSerializer.DeserializeAsync(stream, JsonContext.Default.FlatContainerVersionList, cancellationToken: token); - var result = -#if NETSTANDARD - new HashSet(); -#else - new HashSet(capacity: json.Versions?.Count ?? 0); -#endif + var result = new HashSet(capacity: json.Versions?.Count ?? 0); foreach (var versionString in json.Versions ?? []) { diff --git a/src/NuGet.Core/NuGet.Protocol/Resources/VulnerabilityInfoResourceV3.cs b/src/NuGet.Core/NuGet.Protocol/Resources/VulnerabilityInfoResourceV3.cs index 4bbbdfd0c84..9112963ca77 100644 --- a/src/NuGet.Core/NuGet.Protocol/Resources/VulnerabilityInfoResourceV3.cs +++ b/src/NuGet.Core/NuGet.Protocol/Resources/VulnerabilityInfoResourceV3.cs @@ -197,12 +197,7 @@ public async Task GetVulnerabilityInfoAsync(SourceCa private IReadOnlyList GetValidIndexEntries(IReadOnlyList indexEntries, ref List? exceptions) { List validIndexEntries = new(indexEntries.Count); - HashSet pageNames = -#if NETSTANDARD - new(comparer: StringComparer.InvariantCultureIgnoreCase); -#else - new(indexEntries.Count, StringComparer.InvariantCultureIgnoreCase); -#endif + HashSet pageNames = new(indexEntries.Count, StringComparer.InvariantCultureIgnoreCase); for (int i = 0; i < indexEntries.Count; i++) {