Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions build/Shared/DeconstructionExtensions.cs

This file was deleted.

4 changes: 1 addition & 3 deletions build/Shared/NullableAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still have 1 project that targets NS2.0 (NuGet.VisualStudio.Contracts), so in case we want to enable nullability there we should keep the NS2.0 support in this file.

#if NETFRAMEWORK

namespace System.Diagnostics.CodeAnalysis
{
#if !NETSTANDARD2_1
/// <summary>Specifies that null is allowed as an input even if the corresponding type disallows it.</summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)]
#if SYSTEM_PRIVATE_CORELIB
Expand Down Expand Up @@ -135,7 +134,6 @@ sealed class DoesNotReturnIfAttribute : Attribute
/// <summary>Gets the condition parameter value.</summary>
public bool ParameterValue { get; }
}
#endif

/// <summary>Specifies that the method or property will ensure that the listed field and property members have not-null values.</summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public bool Equals(FileSystemInfo x, FileSystemInfo y)
/// <returns>A hash code for the specified <see cref="FileSystemInfo" /> object's <see cref="FileSystemInfo.FullName" /> property..</returns>
public int GetHashCode(FileSystemInfo obj)
{
#if NETFRAMEWORK || NETSTANDARD
#if NETFRAMEWORK
return obj.FullName.GetHashCode();
#else
return obj.FullName.GetHashCode(StringComparison.Ordinal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/NuGet.Core/NuGet.Commands/Internal/HashCodeCombiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;

#if !NETFRAMEWORK && !NETSTANDARD
#if NET
using System;
#endif

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,7 @@ public void AddItem(GraphItem<TItem> item)
{
if (!existingItem.Equals(item))
{
#if NETSTANDARD2_0
_storage = new HashSet<GraphItem<TItem>>() { existingItem, item };
#else
_storage = new HashSet<GraphItem<TItem>>(capacity: 3) { existingItem, item };
#endif
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to suggest it shouldn't be removed.
This seems like a significant decision, so we either need this reverted, or explained why it's unnecessary.

Either way I would've loved to see this called out in the PR description to help the reviewer.

// 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<byte>.Shared.Rent(bufferSize);

int bytesRead;
while ((bytesRead = inputStream.Read(buffer, offset: 0, buffer.Length)) != 0)
{
outputStream.Write(buffer, offset: 0, bytesRead);
}

ArrayPool<byte>.Shared.Return(buffer);
#else
inputStream.CopyTo(outputStream);
#endif
}

internal class Testable
{
// Only files smaller than this value will be mmap'ed
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -136,7 +110,7 @@ internal virtual void FileStreamCopy(Stream inputStream, string fileFullPath)
{
using (var outputStream = NuGetExtractionFileIO.CreateFile(fileFullPath))
{
CopyTo(inputStream, outputStream);
inputStream.CopyTo(outputStream);
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/NuGet.Core/NuGet.Packaging/RuntimeModel/RuntimeGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,7 @@ public IEnumerable<RuntimePackageDependency> 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<RuntimePackageDependency>();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 0 additions & 4 deletions src/NuGet.Core/NuGet.ProjectModel/ProjectRestoreMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,7 @@ public bool Equals(ProjectRestoreMetadata other)

private HashSet<string> GetSources(IList<PackageSource> sources)
{
#if NETSTANDARD2_0
var setSources = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
#else
var setSources = new HashSet<string>(sources.Count, StringComparer.OrdinalIgnoreCase);
#endif
for (var i = 0; i < sources.Count; i++)
{
setSources.Add(sources[i].Source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool> DangerousAcceptAnyServerCertificateValidator =
(message, certificate, chain, policyErrors) => true;
#endif

public HttpHandlerResourceV3Provider()
: this(ProxyCache.Instance)
{
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,23 +432,12 @@ private static bool TryGetVersionString(NuGetVersion version, HashSet<NuGetVersi
return false;
}

#if !NETSTANDARD
if (!packageVersions.TryGetValue(version, out NuGetVersion? originalVersion))
{
versionString = null;
return false;
}
versionString = originalVersion.ToNormalizedString();
#else
// .NET Standard 2.0 doesn't support HashSet<T>.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;
}
Expand Down Expand Up @@ -582,12 +571,7 @@ private static async Task<HashSet<NuGetVersion>> ConsumeFlatContainerIndexAsync(
{
var json = await JsonSerializer.DeserializeAsync(stream, JsonContext.Default.FlatContainerVersionList, cancellationToken: token);

var result =
#if NETSTANDARD
new HashSet<NuGetVersion>();
#else
new HashSet<NuGetVersion>(capacity: json.Versions?.Count ?? 0);
#endif
var result = new HashSet<NuGetVersion>(capacity: json.Versions?.Count ?? 0);

foreach (var versionString in json.Versions ?? [])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,7 @@ public async Task<GetVulnerabilityInfoResult> GetVulnerabilityInfoAsync(SourceCa
private IReadOnlyList<V3VulnerabilityIndexEntry> GetValidIndexEntries(IReadOnlyList<V3VulnerabilityIndexEntry> indexEntries, ref List<Exception>? exceptions)
{
List<V3VulnerabilityIndexEntry> validIndexEntries = new(indexEntries.Count);
HashSet<string> pageNames =
#if NETSTANDARD
new(comparer: StringComparer.InvariantCultureIgnoreCase);
#else
new(indexEntries.Count, StringComparer.InvariantCultureIgnoreCase);
#endif
HashSet<string> pageNames = new(indexEntries.Count, StringComparer.InvariantCultureIgnoreCase);

for (int i = 0; i < indexEntries.Count; i++)
{
Expand Down