Resolving relative application base paths
This commit is contained in:
parent
906ed5f0fb
commit
79df7c9ca7
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting.Builder;
|
using Microsoft.AspNetCore.Hosting.Builder;
|
||||||
|
|
@ -224,7 +225,7 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
{
|
{
|
||||||
public WrappedApplicationEnvironment(string applicationBasePath, IApplicationEnvironment env)
|
public WrappedApplicationEnvironment(string applicationBasePath, IApplicationEnvironment env)
|
||||||
{
|
{
|
||||||
ApplicationBasePath = applicationBasePath;
|
ApplicationBasePath = ResolvePath(applicationBasePath);
|
||||||
ApplicationName = env.ApplicationName;
|
ApplicationName = env.ApplicationName;
|
||||||
ApplicationVersion = env.ApplicationVersion;
|
ApplicationVersion = env.ApplicationVersion;
|
||||||
RuntimeFramework = env.RuntimeFramework;
|
RuntimeFramework = env.RuntimeFramework;
|
||||||
|
|
@ -238,5 +239,22 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
|
|
||||||
public FrameworkName RuntimeFramework { get; }
|
public FrameworkName RuntimeFramework { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string ResolvePath(string applicationBasePath)
|
||||||
|
{
|
||||||
|
if (Path.IsPathRooted(applicationBasePath))
|
||||||
|
{
|
||||||
|
return applicationBasePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
var basePath =
|
||||||
|
#if NET451
|
||||||
|
(string)AppDomain.CurrentDomain.GetData("APP_CONTEXT_BASE_DIRECTORY") ??
|
||||||
|
AppDomain.CurrentDomain.BaseDirectory;
|
||||||
|
#else
|
||||||
|
AppContext.BaseDirectory;
|
||||||
|
#endif
|
||||||
|
return Path.Combine(Path.GetFullPath(basePath), applicationBasePath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -304,6 +304,19 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
Assert.Equal("/foo/bar", host.Services.GetService<IApplicationEnvironment>().ApplicationBasePath);
|
Assert.Equal("/foo/bar", host.Services.GetService<IApplicationEnvironment>().ApplicationBasePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void RelativeApplicationBaseAreResolved()
|
||||||
|
{
|
||||||
|
var builder = new ConfigurationBuilder();
|
||||||
|
var host = new WebHostBuilder()
|
||||||
|
.UseApplicationBasePath("bar")
|
||||||
|
.UseServer(new TestServer())
|
||||||
|
.UseStartup("Microsoft.AspNetCore.Hosting.Tests")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
Assert.Equal(Path.GetFullPath("bar"), host.Services.GetService<IApplicationEnvironment>().ApplicationBasePath);
|
||||||
|
}
|
||||||
|
|
||||||
private IWebHostBuilder CreateWebHostBuilder()
|
private IWebHostBuilder CreateWebHostBuilder()
|
||||||
{
|
{
|
||||||
var vals = new Dictionary<string, string>
|
var vals = new Dictionary<string, string>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue