Identify version for application and components for Backend(.NET Core) and FrontEnd(Angular)–part 2- backend
Part1 : Introduction and Concepts
Part 2: Obtaining BackEnd Components Version
Part 3: Obtaining FrontEnd Component Version and Final Library
NPM component
Copy paste NET code
Identifying the version of the dll’s used on the backend is fairly simple. All we need is to iterate into the current directory and find the version of the dlls. It is just a simple controller that receives via Dependency Injection the path to the current directory. It is no harder than that code:
[HttpGet] public FileVersionInfo[] GetVersions([FromServices] IHostingEnvironment hosting) { var dirPath = hosting.ContentRootPath; var ret = new List<FileVersionInfo>(); var files = Directory.EnumerateFiles(dirPath, "*.dll", SearchOption.AllDirectories).Union(Directory.EnumerateFiles(dirPath, "*.exe", SearchOption.AllDirectories)); foreach (string item in files) { try { var info = FileVersionInfo.GetVersionInfo(item); ret.Add(info); } catch (Exception) { //TODO: log } } return ret.ToArray(); } }
Leave a Reply