Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove dependencies on Microsoft.DotNet.InternalAbstractions and Micr…
…osoft.Extensions.DependencyModel (and all downstream dependencies, including Newtonsoft.Json) (another fix for #1060)
- Loading branch information
1 parent
50f4e97
commit 557e1d5
Showing
53 changed files
with
3,604 additions
and
63 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/common/Microsoft.DotNet.PlatformAbstractions/ApplicationEnvironment.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#if NET452 || NETSTANDARD1_5 || NETCOREAPP1_0 | ||
|
||
using System; | ||
using System.IO; | ||
|
||
namespace Internal.Microsoft.DotNet.PlatformAbstractions | ||
{ | ||
internal static class ApplicationEnvironment | ||
{ | ||
public static string ApplicationBasePath { get; } = GetApplicationBasePath(); | ||
|
||
private static string GetApplicationBasePath() | ||
{ | ||
var basePath = | ||
#if NET452 | ||
(string)AppDomain.CurrentDomain.GetData("APP_CONTEXT_BASE_DIRECTORY") ?? | ||
AppDomain.CurrentDomain.BaseDirectory; | ||
#else | ||
AppContext.BaseDirectory; | ||
#endif | ||
return Path.GetFullPath(basePath); | ||
} | ||
} | ||
} | ||
|
||
#endif |
62 changes: 62 additions & 0 deletions
62
src/common/Microsoft.DotNet.PlatformAbstractions/HashCodeCombiner.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#if NET452 || NETSTANDARD1_5 || NETCOREAPP1_0 | ||
|
||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Internal.Microsoft.DotNet.PlatformAbstractions | ||
{ | ||
internal struct HashCodeCombiner | ||
{ | ||
private long _combinedHash64; | ||
|
||
public int CombinedHash | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
get { return _combinedHash64.GetHashCode(); } | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
private HashCodeCombiner(long seed) | ||
{ | ||
_combinedHash64 = seed; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public void Add(int i) | ||
{ | ||
_combinedHash64 = ((_combinedHash64 << 5) + _combinedHash64) ^ i; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public void Add(string s) | ||
{ | ||
var hashCode = (s != null) ? s.GetHashCode() : 0; | ||
Add(hashCode); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public void Add(object o) | ||
{ | ||
var hashCode = (o != null) ? o.GetHashCode() : 0; | ||
Add(hashCode); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public void Add<TValue>(TValue value, IEqualityComparer<TValue> comparer) | ||
{ | ||
var hashCode = value != null ? comparer.GetHashCode(value) : 0; | ||
Add(hashCode); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static HashCodeCombiner Start() | ||
{ | ||
return new HashCodeCombiner(0x1505L); | ||
} | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
The code in this folder was imported from: | ||
|
||
https://github.com/dotnet/core-setup/tree/v2.0.1/src/managed/Microsoft.DotNet.PlatformAbstractions | ||
|
||
The original license file can be found here: | ||
|
||
https://github.com/dotnet/core-setup/blob/v2.0.1/LICENSE.TXT | ||
|
||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 .NET Foundation | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
59 changes: 59 additions & 0 deletions
59
src/common/Microsoft.DotNet.PlatformAbstractions/Native/NativeMethods.Darwin.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#if NET452 || NETSTANDARD1_5 || NETCOREAPP1_0 | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Internal.Microsoft.DotNet.PlatformAbstractions.Native | ||
{ | ||
internal static partial class NativeMethods | ||
{ | ||
public static class Darwin | ||
{ | ||
private const int CTL_KERN = 1; | ||
private const int KERN_OSRELEASE = 2; | ||
|
||
public unsafe static string GetKernelRelease() | ||
{ | ||
const uint BUFFER_LENGTH = 32; | ||
|
||
var name = stackalloc int[2]; | ||
name[0] = CTL_KERN; | ||
name[1] = KERN_OSRELEASE; | ||
|
||
var buf = stackalloc byte[(int)BUFFER_LENGTH]; | ||
var len = stackalloc uint[1]; | ||
*len = BUFFER_LENGTH; | ||
|
||
try | ||
{ | ||
// If the buffer isn't big enough, it seems sysctl still returns 0 and just sets len to the | ||
// necessary buffer size. This appears to be contrary to the man page, but it's easy to detect | ||
// by simply checking len against the buffer length. | ||
if (sysctl(name, 2, buf, len, IntPtr.Zero, 0) == 0 && *len < BUFFER_LENGTH) | ||
{ | ||
return Marshal.PtrToStringAnsi((IntPtr)buf, (int)*len); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new PlatformNotSupportedException("Error reading Darwin Kernel Version", ex); | ||
} | ||
throw new PlatformNotSupportedException("Unknown error reading Darwin Kernel Version"); | ||
} | ||
|
||
[DllImport("libc")] | ||
private unsafe static extern int sysctl( | ||
int* name, | ||
uint namelen, | ||
byte* oldp, | ||
uint* oldlenp, | ||
IntPtr newp, | ||
uint newlen); | ||
} | ||
} | ||
} | ||
|
||
#endif |
39 changes: 39 additions & 0 deletions
39
src/common/Microsoft.DotNet.PlatformAbstractions/Native/NativeMethods.Unix.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#if NET452 | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Internal.Microsoft.DotNet.PlatformAbstractions.Native | ||
{ | ||
internal static partial class NativeMethods | ||
{ | ||
public static class Unix | ||
{ | ||
public unsafe static string GetUname() | ||
{ | ||
// Utsname shouldn't be larger than 2K | ||
var buf = stackalloc byte[2048]; | ||
|
||
try | ||
{ | ||
if (uname((IntPtr)buf) == 0) | ||
{ | ||
return Marshal.PtrToStringAnsi((IntPtr)buf); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new PlatformNotSupportedException("Error reading Unix name", ex); | ||
} | ||
throw new PlatformNotSupportedException("Unknown error reading Unix name"); | ||
} | ||
|
||
[DllImport("libc")] | ||
private static extern int uname(IntPtr utsname); | ||
} | ||
} | ||
} | ||
#endif |
47 changes: 47 additions & 0 deletions
47
src/common/Microsoft.DotNet.PlatformAbstractions/Native/NativeMethods.Windows.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#if NET452 || NETSTANDARD1_5 || NETCOREAPP1_0 | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
namespace Internal.Microsoft.DotNet.PlatformAbstractions.Native | ||
{ | ||
internal static partial class NativeMethods | ||
{ | ||
public static class Windows | ||
{ | ||
[StructLayout(LayoutKind.Sequential)] | ||
internal struct RTL_OSVERSIONINFOEX | ||
{ | ||
internal uint dwOSVersionInfoSize; | ||
internal uint dwMajorVersion; | ||
internal uint dwMinorVersion; | ||
internal uint dwBuildNumber; | ||
internal uint dwPlatformId; | ||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] | ||
internal string szCSDVersion; | ||
} | ||
|
||
// This call avoids the shimming Windows does to report old versions | ||
[DllImport("ntdll")] | ||
private static extern int RtlGetVersion(out RTL_OSVERSIONINFOEX lpVersionInformation); | ||
|
||
internal static string RtlGetVersion() | ||
{ | ||
RTL_OSVERSIONINFOEX osvi = new RTL_OSVERSIONINFOEX(); | ||
osvi.dwOSVersionInfoSize = (uint)Marshal.SizeOf(osvi); | ||
if (RtlGetVersion(out osvi) == 0) | ||
{ | ||
return $"{osvi.dwMajorVersion}.{osvi.dwMinorVersion}.{osvi.dwBuildNumber}"; | ||
} | ||
else | ||
{ | ||
return null; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#endif |
Oops, something went wrong.