Skip to main content

How to read Project.json file in ASP.NET Core 1.0

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.

Read Project.json file in ASP.NET Core 1.0

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 Buy Me A Coffee

One thought to “How to read Project.json file in ASP.NET Core 1.0”

  1. This is a great thing. I am implementing something similar and could use your example.
    Could you please share your source code? I don’t seem to find it on a post

Leave a Reply

Your email address will not be published. Required fields are marked *