【发布时间】:2010-12-30 07:02:28
【问题描述】:
我已经实现了许多帖子中提到的 fusion.dll 包装器,现在发现我需要确定是否需要更新的至少一个 dll 不是使用构建号和修订号。因此,我无法比较版本号,需要比较上次修改日期。
fusion.dll 或其包装器没有这样的方法,我认为这很公平,但我如何确定 dll 的“真实”路径,以便我可以发现它的最后修改日期。
到目前为止我的代码:
private DateTime getGACVersionLastModified(string DLLName)
{
FileInfo fi = new FileInfo(DLLName);
string dllName = fi.Name.Replace(fi.Extension, "");
DateTime versionDT = new DateTime(1960,01,01);
IAssemblyEnum ae = AssemblyCache.CreateGACEnum();
IAssemblyName an;
AssemblyName name;
while (AssemblyCache.GetNextAssembly(ae, out an) == 0)
{
try
{
name = GetAssemblyName(an);
if (string.Compare(name.Name, dllName, true) == 0)
{
FileInfo dllfi = new FileInfo(string.Format("{0}.dll", name.Name));
if (DateTime.Compare(dllfi.LastWriteTime, versionDT) >= 0)
versionDT = dllfi.LastWriteTime;
}
}
catch (Exception ex)
{
logger.FatalException("Unable to get version number: ", ex);
}
}
return versionDT;
}
【问题讨论】:
-
我已经很久没有使用 Fusion API 了。但是您是否尝试过调用 IAssemblyCache.QueryAssemblyInfo ?它应该返回一个文件路径。
标签: c# reflection assemblies gac