Skip to content

Instantly share code, notes, and snippets.

@rena2019
Created April 2, 2019 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rena2019/2cffdfd7bf527bd1773ebc8455cdfd21 to your computer and use it in GitHub Desktop.
Save rena2019/2cffdfd7bf527bd1773ebc8455cdfd21 to your computer and use it in GitHub Desktop.
// Display File Version Info
// compile with C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe <filename>
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;//Assembly
namespace MyFileInfo
{
class FileInfo
{
static void Main(String[] args)
{
String[] files;
if (args.Length > 0) {
files = Directory.GetFiles(args[0]);
} else {
files = Directory.GetFiles(".");
}
foreach(String file in files) {
Console.WriteLine(file);
FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(file);
// Print the file name and version number.
Console.WriteLine(" File: " + myFileVersionInfo.FileDescription +
", Version number: " + myFileVersionInfo.FileVersion +
", ProductName: " + myFileVersionInfo.ProductName +
", IsDebug: " + myFileVersionInfo.IsDebug);
//string assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
string assemblyVersion = "";
string fileVersion = "";
string productVersion = "";
try {
assemblyVersion = Assembly.LoadFile(file).GetName().Version.ToString();
fileVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;
productVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion;
}catch(Exception) { }
Console.WriteLine(" assemblyVersion: " + assemblyVersion + ", fileVersion: " + fileVersion + ", productVersion: " + productVersion);
Console.WriteLine(" Date modified: " + System.IO.File.GetLastWriteTime(file));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment