From dbcee46466da13eb25e6de6204b95829f73c4ca1 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Wed, 20 Feb 2019 18:23:27 -0600 Subject: [PATCH 1/2] Remove DependencyModel's dependency on PlatformAbstractions Working towards #5213 --- .../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/managed/Microsoft.Extensions.DependencyModel/ApplicationEnvironment.cs diff --git a/src/managed/Microsoft.Extensions.DependencyModel/ApplicationEnvironment.cs b/src/managed/Microsoft.Extensions.DependencyModel/ApplicationEnvironment.cs new file mode 100644 index 0000000000..0c6536997f --- /dev/null +++ b/src/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() + { + var 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/managed/Microsoft.Extensions.DependencyModel/EnvironmentWrapper.cs b/src/managed/Microsoft.Extensions.DependencyModel/EnvironmentWrapper.cs index c8254b1a6c..8b657e9d81 100644 --- a/src/managed/Microsoft.Extensions.DependencyModel/EnvironmentWrapper.cs +++ b/src/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/managed/Microsoft.Extensions.DependencyModel/IEnvironment.cs b/src/managed/Microsoft.Extensions.DependencyModel/IEnvironment.cs index c468709cc5..d22e00a18e 100644 --- a/src/managed/Microsoft.Extensions.DependencyModel/IEnvironment.cs +++ b/src/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/managed/Microsoft.Extensions.DependencyModel/Microsoft.Extensions.DependencyModel.csproj b/src/managed/Microsoft.Extensions.DependencyModel/Microsoft.Extensions.DependencyModel.csproj index 2cddc4e727..a23f5324de 100644 --- a/src/managed/Microsoft.Extensions.DependencyModel/Microsoft.Extensions.DependencyModel.csproj +++ b/src/managed/Microsoft.Extensions.DependencyModel/Microsoft.Extensions.DependencyModel.csproj @@ -8,6 +8,10 @@ 7.3 + + + +