#74 - Parse the project.json file with Newtonsoft directly.
This commit is contained in:
parent
8a66871139
commit
c47d6d0c78
|
|
@ -17,7 +17,8 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.Framework.ConfigurationModel;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Microsoft.AspNet.Hosting
|
||||
{
|
||||
|
|
@ -38,17 +39,19 @@ namespace Microsoft.AspNet.Hosting
|
|||
|
||||
public static string GetWebRoot(string applicationBasePath)
|
||||
{
|
||||
try
|
||||
var webroot = applicationBasePath;
|
||||
using (var stream = File.OpenRead(Path.Combine(applicationBasePath, "project.json")))
|
||||
{
|
||||
var config = new Configuration();
|
||||
config.AddJsonFile(Path.Combine(applicationBasePath, "project.json"));
|
||||
var webroot = config.Get("webroot") ?? string.Empty;
|
||||
return Path.GetFullPath(Path.Combine(applicationBasePath, webroot));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return applicationBasePath;
|
||||
using (var reader = new JsonTextReader(new StreamReader(stream)))
|
||||
{
|
||||
var project = JObject.Load(reader);
|
||||
if (project.TryGetValue("webroot", out var token))
|
||||
{
|
||||
webroot = Path.Combine(applicationBasePath, token.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return Path.GetFullPath(webroot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@
|
|||
"Microsoft.AspNet.PipelineCore": "1.0.0-*",
|
||||
"Microsoft.AspNet.Security.DataProtection": "1.0.0-*",
|
||||
"Microsoft.Framework.ConfigurationModel": "1.0.0-*",
|
||||
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-*",
|
||||
"Microsoft.Framework.DependencyInjection": "1.0.0-*",
|
||||
"Microsoft.Framework.Logging": "1.0.0-*",
|
||||
"Microsoft.Framework.Runtime.Interfaces": "1.0.0-*"
|
||||
"Microsoft.Framework.Runtime.Interfaces": "1.0.0-*",
|
||||
"Newtonsoft.Json": "6.0.4"
|
||||
},
|
||||
"frameworks": {
|
||||
"aspnet50": {},
|
||||
|
|
|
|||
Loading…
Reference in New Issue