3

パスが指定されているときに「c#」でdllファイルのファイルバージョンを確認したい。path = "\ x \ y\z.dll"と仮定します。

パスが指定されているときにz.dllのファイルバージョンを見つける方法は?

注:Compact Framework3.5SP1を使用しています

4

2 に答える 2

8
// Get the file version for the notepad.
FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(Environment.SystemDirectory + "\\Notepad.exe");

// Print the file name and version number.
Console.WriteLine("File: " + myFileVersionInfo.FileDescription + '\n' +
                  "Version number: " + myFileVersionInfo.FileVersion);

から: http://msdn.microsoft.com/en-us/library/system.diagnostics.fileversioninfo.fileversion.aspx

だからあなたのために:

FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(@"\x\y\z.dll");

これは、dll が .net または Win32 の場合に機能します。リフレクション メソッドは、dll が .net の場合にのみ機能します。

于 2012-07-25T08:00:42.503 に答える
2

通常のフレームワーク

.NET DLL の場合は、Reflection を使用できます。

using System.Reflection;

Assembly assembly = Assembly.LoadFrom("\x\y\z.dll");
Version ver = assembly.GetName().Version;

そうでない場合は、System.Diagnostics を使用できます。

using System.Diagnostics;

static string GetDllVersion(string dllPath)
{
  FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(dllPath);
  return myFileVersionInfo.FileVersion;
}

// Sample invokation
string result = GetDllVersion(@"C:\Program Files (x86)\Google\Chrome\Application\20.0.1132.57\chrome.dll");
// result value **20.0.1132.57**

コンパクトなフレームワーク

.NET Compact Frameworkを使用している場合、 FileVersionInfoにアクセスできません

このstackoverflowの質問を確認できます。固有の回答には、問題を解決するコードを含むブログへのリンクがあります。

于 2012-07-25T08:02:28.477 に答える