diff --git a/src/managed/Microsoft.Extensions.DependencyModel/ApplicationEnvironment.cs b/src/managed/Microsoft.Extensions.DependencyModel/ApplicationEnvironment.cs new file mode 100644 index 0000000000..2a7e528893 --- /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() + { + 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/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 + + + +