Last post Feb 03, 2016 03:26 PM by Eagle_f90
Feb 02, 2016 08:15 PM|Eagle_f90|LINK
The project.json file that contains a `version' field. I want to be able to read this so when I log bugs I can log the version that caused it. I have done some google searches but all I find is information on what the new file is for and now
to use it to add dependences. I was thinking I could use
NewtonSoft to deserialize it but that requires I know the exact location of the file on every deployment, which I wont.
Is there some built in method to read from the project.json file to get the version number? If this is not possible what would be the best method to track the version number and allow access to it as needed from controller methods?
Feb 02, 2016 10:59 PM|Rion Williams|LINK
Sure, you should be able to read it in as you would a normal config file within your Startup.cs (or some other area of your application) :
public Startup(IHostingEnvironment env)
// Read your project.json file
var project = new ConfigurationBuilder().AddJsonFile("project.json").Build();
// Pull the version from it
var version = project["version"]; // yields "1.0.0-*" or something similar...
// Set up configuration sources here
Feb 03, 2016 03:26 PM|Eagle_f90|LINK
It is already built in the Startup.cs file, is there no other way of reading from it then having to completely build a configuration ever time that seems like it would eat a lot of resources on a heavy site and slow it down having to build a configuration
over and over and over.