From 7acfee357058469e1133bcb09d3142fda947b1e4 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Fri, 1 Mar 2019 11:46:42 -0600 Subject: [PATCH] Remove DependencyModel's dependency on PlatformAbstractions (dotnet/core-setup#5218) * Remove DependencyModel's dependency on PlatformAbstractions Working towards dotnet/core-setup#5213 Commit migrated from https://github.com/dotnet/core-setup/commit/e43465a759f9d887aa8d605faeaf4508c581f2db --- .../ApplicationEnvironment.cs | 25 +++++++++ .../EnvironmentWrapper.cs | 6 ++ .../IEnvironment.cs | 1 + ...icrosoft.Extensions.DependencyModel.csproj | 14 ++--- .../AppBaseCompilationAssemblyResolver.cs | 1 - .../DotNetReferenceAssembliesPathResolver.cs | 8 +-- .../PackageCompilationAssemblyResolver.cs | 55 +++++++++---------- .../ReferenceAssemblyPathResolver.cs | 13 ++--- .../EnvironmentMockBuilder.cs | 18 +++++- .../PackageResolverTest.cs | 11 ++-- .../ReferenceAssemblyResolverTests.cs | 14 +++-- 11 files changed, 103 insertions(+), 63 deletions(-) create mode 100644 src/installer/managed/Microsoft.Extensions.DependencyModel/ApplicationEnvironment.cs diff --git a/src/installer/managed/Microsoft.Extensions.DependencyModel/ApplicationEnvironment.cs b/src/installer/managed/Microsoft.Extensions.DependencyModel/ApplicationEnvironment.cs new file mode 100644 index 0000000000000..2a7e528893a3c --- /dev/null +++ b/src/installer/managed/Microsoft.Extensions.DependencyModel/ApplicationEnvironment.cs @@ -0,0 +1,25 @@ +// 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. + +using System; +using System.IO; + +namespace Microsoft.Extensions.DependencyModel +{ + internal static class ApplicationEnvironment + { + public static string ApplicationBasePath { get; } = GetApplicationBasePath(); + + private static string GetApplicationBasePath() + { + string basePath = +#if NET451 + (string)AppDomain.CurrentDomain.GetData("APP_CONTEXT_BASE_DIRECTORY") ?? + AppDomain.CurrentDomain.BaseDirectory; +#else + AppContext.BaseDirectory; +#endif + return Path.GetFullPath(basePath); + } + } +} diff --git a/src/installer/managed/Microsoft.Extensions.DependencyModel/EnvironmentWrapper.cs b/src/installer/managed/Microsoft.Extensions.DependencyModel/EnvironmentWrapper.cs index c8254b1a6c305..8b657e9d8110d 100644 --- a/src/installer/managed/Microsoft.Extensions.DependencyModel/EnvironmentWrapper.cs +++ b/src/installer/managed/Microsoft.Extensions.DependencyModel/EnvironmentWrapper.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.DependencyModel { @@ -13,5 +14,10 @@ public string GetEnvironmentVariable(string name) { return Environment.GetEnvironmentVariable(name); } + + public bool IsWindows() + { + return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + } } } \ No newline at end of file diff --git a/src/installer/managed/Microsoft.Extensions.DependencyModel/IEnvironment.cs b/src/installer/managed/Microsoft.Extensions.DependencyModel/IEnvironment.cs index c468709cc51ef..d22e00a18ea92 100644 --- a/src/installer/managed/Microsoft.Extensions.DependencyModel/IEnvironment.cs +++ b/src/installer/managed/Microsoft.Extensions.DependencyModel/IEnvironment.cs @@ -6,5 +6,6 @@ namespace Microsoft.Extensions.DependencyModel internal interface IEnvironment { string GetEnvironmentVariable(string name); + bool IsWindows(); } } \ No newline at end of file diff --git a/src/installer/managed/Microsoft.Extensions.DependencyModel/Microsoft.Extensions.DependencyModel.csproj b/src/installer/managed/Microsoft.Extensions.DependencyModel/Microsoft.Extensions.DependencyModel.csproj index 2cddc4e727f2f..a23f5324de677 100644 --- a/src/installer/managed/Microsoft.Extensions.DependencyModel/Microsoft.Extensions.DependencyModel.csproj +++ b/src/installer/managed/Microsoft.Extensions.DependencyModel/Microsoft.Extensions.DependencyModel.csproj @@ -8,6 +8,10 @@ 7.3 + + + +