One of my colleague asked me how to read version number from Project.json file. He needed the version number for error logging. So I gave him the solution and thought of sharing with you. So in this quick post, find sample code to read Project.json file in ASP.NET Core 1.0.
// Read project.json file var projConfig = new ConfigurationBuilder().AddJsonFile("project.json").Build(); var appVersion = projConfig["version"]; //Output version number var mvcVersion = projConfig["dependencies:Microsoft.AspNet.Mvc"]; // Output MVC version
Below is the screenshot of
projConfig variable when viewed in quick watch while debugging. Just watch out here for key formation.
The above will also work for reading other JSON files. All you need to replace is name of json file and obviously the keys name.
Cheers!!!!PS: If you found this content valuable and want to return the favour, then