Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Commit

Permalink
#74 - Parse the project.json file with Newtonsoft directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tratcher committed Sep 15, 2014
1 parent 8a66871 commit 6237506
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
21 changes: 15 additions & 6 deletions src/Microsoft.AspNet.Hosting/HostingUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

using System;
using System.IO;
using Microsoft.Framework.ConfigurationModel;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Microsoft.AspNet.Hosting
{
Expand All @@ -38,17 +39,25 @@ internal static Tuple<string, string> SplitTypeName(string identifier)

public static string GetWebRoot(string applicationBasePath)
{
var webroot = applicationBasePath;
try
{
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));
using (var stream = new FileStream(Path.Combine(applicationBasePath, "project.json"), FileMode.Open, FileAccess.Read))
{
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());
}
}
}
}
catch (Exception)
{
return applicationBasePath;
}
return Path.GetFullPath(webroot);
}
}
}
4 changes: 2 additions & 2 deletions src/Microsoft.AspNet.Hosting/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand Down

0 comments on commit 6237506

Please sign in to comment.