I am trying to get the file version using .net core.
Method1
string file = @"C:\somefile.dll";
Console.WriteLine(AssemblyName.GetAssemblyName(file).Version.ToString());
Problem in Method1 is if file is not assembly it throws BadImageFormatException
Method2
string file = @"C:\hostpolicy.dll";
FileVersionInfo fileversion = FileVersionInfo.GetVersionInfo(file);
Console.WriteLine(fileversion.FileVersion);
Problem in above code is it returns result different than ones presented in the windows file explorer.
See the attached image.
The file version presented in windows explorer is "2.2.27414.6",
however the one i get using FileVersion property is "2.2.27414.06 @BuiltBy: dlab14-DDVSOWINAGE021 @Branch: release/2.2 @SrcCode: https://github.com/dotnet/core-setup/tree/6b8ad509b6a48bcca07e8c413d6ffed8988547cc. Commit Hash: 6b8ad509b6a48bcca07e8c413d6ffed8988547cc".