Tuesday, February 16, 2016

Reading version information from project.json

As of now, many of you are aware about the information stored in project.json file in ASP.NET Core 1.0. My this blog post will tell, how to retrieve the version number from project.json file.


Below is the screenshot of my json file:




















And below is the code to get the version number:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
            // Reading project.json file
            var projConfig = new ConfigurationBuilder().AddJsonFile("project.json").Build();

            //app version number
            var appVersion = projConfig["version"];

            // SQL Server version number
            var sqlServerVersion = projConfig["dependencies:EntityFramework.MicrosoftSqlServer"]; 
}
Hope this post was helpful.
Mothertouch Round Walker (Blue)

No comments:

Post a Comment