如何确定Compact Framework 3.5中的dll文件的文件版本 [英] How to determine file version of dll file in Compact Framework 3.5

查看:256
本文介绍了如何确定Compact Framework 3.5中的dll文件的文件版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当指定路径时,我想确定c#中的dll文件的文件版本。
假设path =\x\y\z.dll。



如果给定路径,如何查找z.dll的文件版本?



注意:我使用Compact Framework 3.5 SP1

解决方案

正常框架



如果它是一个.NET DLL,您可以使用Reflection。

  using System.Reflection; 

Assembly assembly = Assembly.LoadFrom(\x\y\z.dll);
版本ver = assembly.GetName()。版本;

如果没有,可以使用System.Diagnostics:

 使用System.Diagnostics; 

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

//样例调用
string result = GetDllVersion(@C:\Program Files(x86)\Google\Chrome\Application\20.0。 1132.57\chrome.dll);
//结果值** 20.0.1132.57 **

紧凑框架



如果您使用 .NET Compact Framework ,则无法访问 FileVersionInfo p>

您可以检查这个 stackoverflow问题。在唯一答案中,您有一个链接到一个博客,代码解决您的问题。


I want to determine the file version of dll file in 'c#' when the path is specified. Suppose path = "\x\y\z.dll" .

How to find the file version of z.dll when path is given?

NOTE: I use Compact Framework 3.5 SP1

解决方案

Normal Framework

If it is a .NET DLL you can use Reflection.

using System.Reflection;

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

If not, you can use 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**

Compact Framework

If you are using .NET Compact Framework you don't have access to FileVersionInfo

You can check this stackoverflow question. In the unique answer you have a link to a blog with code that fixes your problem.

这篇关于如何确定Compact Framework 3.5中的dll文件的文件版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆