diff --git a/src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/PackageBuilder.cs b/src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/PackageBuilder.cs index d273d47e056..e433838a3ec 100644 --- a/src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/PackageBuilder.cs +++ b/src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/PackageBuilder.cs @@ -780,7 +780,11 @@ private HashSet WriteFiles(ZipArchive package, HashSet filesWith } else { +#if NETCOREAPP + filesWithoutExtensions.Add($"/{file.Path.Replace("\\", "/", StringComparison.Ordinal)}"); +#else filesWithoutExtensions.Add($"/{file.Path.Replace("\\", "/")}"); +#endif } } catch diff --git a/src/NuGet.Core/NuGet.Packaging/PackageExtraction/ZipArchiveExtensions.cs b/src/NuGet.Core/NuGet.Packaging/PackageExtraction/ZipArchiveExtensions.cs index 2f1ef3728d3..1d5fbf17744 100644 --- a/src/NuGet.Core/NuGet.Packaging/PackageExtraction/ZipArchiveExtensions.cs +++ b/src/NuGet.Core/NuGet.Packaging/PackageExtraction/ZipArchiveExtensions.cs @@ -35,7 +35,11 @@ public static IEnumerable GetFiles(this ZipArchive zipArchive) private static string UnescapePath(string path) { if (path != null +#if NETCOREAPP + && path.IndexOf('%', StringComparison.Ordinal) > -1) +#else && path.IndexOf('%') > -1) +#endif { return Uri.UnescapeDataString(path); } diff --git a/src/NuGet.Core/NuGet.Packaging/PackageFolderReader.cs b/src/NuGet.Core/NuGet.Packaging/PackageFolderReader.cs index 13fbec03a28..5a71341dffe 100644 --- a/src/NuGet.Core/NuGet.Packaging/PackageFolderReader.cs +++ b/src/NuGet.Core/NuGet.Packaging/PackageFolderReader.cs @@ -150,7 +150,11 @@ public override IEnumerable GetFiles(string folder) /// private static bool IsFileInRoot(string path) { +#if NETCOREAPP + return path.IndexOf('/', StringComparison.Ordinal) == -1; +#else return path.IndexOf('/') == -1; +#endif } /// diff --git a/src/NuGet.Core/NuGet.Packaging/Rules/UpholdBuildConventionRule.cs b/src/NuGet.Core/NuGet.Packaging/Rules/UpholdBuildConventionRule.cs index 936796b6118..29dcd6b530f 100644 --- a/src/NuGet.Core/NuGet.Packaging/Rules/UpholdBuildConventionRule.cs +++ b/src/NuGet.Core/NuGet.Packaging/Rules/UpholdBuildConventionRule.cs @@ -103,7 +103,11 @@ internal class ConventionViolator public ConventionViolator(string filePath, string extension, string expectedFile) { +#if NETCOREAPP + Path = filePath.Replace(filePath.Split('/')[filePath.Count(p => p == '/')], string.Empty, StringComparison.OrdinalIgnoreCase); +#else Path = filePath.Replace(filePath.Split('/')[filePath.Count(p => p == '/')], string.Empty); +#endif Extension = extension; ExpectedPath = expectedFile; } diff --git a/src/NuGet.Core/NuGet.Packaging/Signing/Archive/EndOfCentralDirectoryRecord.cs b/src/NuGet.Core/NuGet.Packaging/Signing/Archive/EndOfCentralDirectoryRecord.cs index f754422a39e..5757e81c8c6 100644 --- a/src/NuGet.Core/NuGet.Packaging/Signing/Archive/EndOfCentralDirectoryRecord.cs +++ b/src/NuGet.Core/NuGet.Packaging/Signing/Archive/EndOfCentralDirectoryRecord.cs @@ -106,7 +106,11 @@ private static void ThrowByteSignatureNotFoundException(byte[] signature) throw new InvalidDataException( string.Format(CultureInfo.CurrentCulture, Strings.ErrorByteSignatureNotFound, +#if NETCOREAPP + BitConverter.ToString(signature).Replace("-", "", StringComparison.Ordinal))); +#else BitConverter.ToString(signature).Replace("-", ""))); +#endif } } -} \ No newline at end of file +} diff --git a/src/NuGet.Core/NuGet.Packaging/Signing/Content/KeyPairFileReader.cs b/src/NuGet.Core/NuGet.Packaging/Signing/Content/KeyPairFileReader.cs index 468fb14e466..f7aa36e0eb5 100644 --- a/src/NuGet.Core/NuGet.Packaging/Signing/Content/KeyPairFileReader.cs +++ b/src/NuGet.Core/NuGet.Packaging/Signing/Content/KeyPairFileReader.cs @@ -73,7 +73,11 @@ public Dictionary ReadSection() private static KeyValuePair GetProperty(string line) { +#if NETCOREAPP + var pos = line.IndexOf(':', StringComparison.Ordinal); +#else var pos = line.IndexOf(':'); +#endif if (pos > 0) { diff --git a/src/NuGet.Core/NuGet.Packaging/Signing/DerEncoding/DerGeneralizedTime.cs b/src/NuGet.Core/NuGet.Packaging/Signing/DerEncoding/DerGeneralizedTime.cs index 20703ea3446..a6eaf5c45e4 100644 --- a/src/NuGet.Core/NuGet.Packaging/Signing/DerEncoding/DerGeneralizedTime.cs +++ b/src/NuGet.Core/NuGet.Packaging/Signing/DerEncoding/DerGeneralizedTime.cs @@ -32,7 +32,11 @@ public static DerGeneralizedTime Read(string decodedTime) throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding); } +#if NETCOREAPP + var decimalIndex = decodedTime.IndexOf('.', StringComparison.Ordinal); +#else var decimalIndex = decodedTime.IndexOf('.'); +#endif var stringToParse = decodedTime; string format; @@ -88,4 +92,4 @@ public static DerGeneralizedTime Read(string decodedTime) throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding); } } -} \ No newline at end of file +} diff --git a/src/NuGet.Core/NuGet.Packaging/Signing/Timestamp/Rfc3161TimestampVerificationUtility.cs b/src/NuGet.Core/NuGet.Packaging/Signing/Timestamp/Rfc3161TimestampVerificationUtility.cs index 46a63c47775..1f6e2da5dbb 100644 --- a/src/NuGet.Core/NuGet.Packaging/Signing/Timestamp/Rfc3161TimestampVerificationUtility.cs +++ b/src/NuGet.Core/NuGet.Packaging/Signing/Timestamp/Rfc3161TimestampVerificationUtility.cs @@ -37,7 +37,7 @@ internal static bool TryReadTSTInfoFromSignedCms( out IRfc3161TimestampTokenInfo tstInfo) { tstInfo = null; - if (timestampCms.ContentInfo.ContentType.Value.Equals(Oids.TSTInfoContentType)) + if (timestampCms.ContentInfo.ContentType.Value.Equals(Oids.TSTInfoContentType, StringComparison.Ordinal)) { tstInfo = Rfc3161TimestampTokenInfoFactory.Create(timestampCms.ContentInfo.Content); return true; diff --git a/src/NuGet.Core/NuGet.Packaging/Signing/Utility/CertificateUtility.cs b/src/NuGet.Core/NuGet.Packaging/Signing/Utility/CertificateUtility.cs index cdf43204c58..36eeaf32269 100644 --- a/src/NuGet.Core/NuGet.Packaging/Signing/Utility/CertificateUtility.cs +++ b/src/NuGet.Core/NuGet.Packaging/Signing/Utility/CertificateUtility.cs @@ -263,7 +263,11 @@ public static string GetHashString(X509Certificate2 certificate, HashAlgorithmNa } var certificateFingerprint = GetHash(certificate, hashAlgorithm); +#if NETCOREAPP + return BitConverter.ToString(certificateFingerprint).Replace("-", "", StringComparison.Ordinal); +#else return BitConverter.ToString(certificateFingerprint).Replace("-", ""); +#endif } /// @@ -325,7 +329,11 @@ public static bool IsSelfIssued(X509Certificate2 certificate) if (reader.HasTag(keyIdentifierTag)) { var keyIdentifier = reader.ReadValue(keyIdentifierTag); +#if NETCOREAPP + var akiKeyIdentifier = BitConverter.ToString(keyIdentifier).Replace("-", "", StringComparison.Ordinal); +#else var akiKeyIdentifier = BitConverter.ToString(keyIdentifier).Replace("-", ""); +#endif return string.Equals(skiExtension.SubjectKeyIdentifier, akiKeyIdentifier, StringComparison.OrdinalIgnoreCase); } @@ -347,4 +355,4 @@ public static IReadOnlyList GetRawDataForCollection(X509Certificate2Coll return certificatesRawData.AsReadOnly(); } } -} \ No newline at end of file +}