アセンブリをロードせずにバージョンを取得するにはどうすればいいですか? 質問する

アセンブリをロードせずにバージョンを取得するにはどうすればいいですか? 質問する

大規模なプログラムの 1 つの小さな関数は、フォルダー内のアセンブリを調べ、古いアセンブリを最新バージョンに置き換えます。これを実現するには、実行中のプロセスにアセンブリを実際にロードせずに、既存のアセンブリ ファイルのバージョン番号を読み取る必要があります。

ベストアンサー1

私は次のものを見つけました記事上で

using System.Reflection;
using System.IO;

...

// Get current and updated assemblies
AssemblyName currentAssemblyName = AssemblyName.GetAssemblyName(currentAssemblyPath);
AssemblyName updatedAssemblyName = AssemblyName.GetAssemblyName(updatedAssemblyPath);

// Compare both versions
if (updatedAssemblyName.Version.CompareTo(currentAssemblyName.Version) <= 0)
{
    // There's nothing to update
    return;
}

// Update older version
File.Copy(updatedAssemblyPath, currentAssemblyPath, true);

おすすめ記事