检查文件是否与所用系统兼容 [英] Checking file if it is compatible in the system used

查看:66
本文介绍了检查文件是否与所用系统兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我想知道有关文件检查的解决方案..
示例:

"example.dll"
我想要获取此文件的版本并将其与运行我的工具所需的版本进行比较.如果它们的版本不同,我希望显示我的工具的最低要求.

我只是C#的新手


谢谢大家.

Hi all,


I want to know a solution regarding file checking..
Example:

"example.dll"
I want to get the file version of this and compare to the version needed in my tool to run. And if they are not the same in version I would like to display the minimum requirement of my tool.

I''m just a novice in C#


Thank you all.

推荐答案

我认为您要关心的不是文件版本,而是使用程序集可执行模块(库)实现的程序集版本和应用程序).您的版本控制方法应基于程序集的版本,而不要基于其他版本.例如,我尝试支持系统,其中应用程序的所有程序集都以与整个系统或应用程序完全相同的版本重新编译所有程序集的方式进行维护.这部分完全在您身上.

您需要知道如何从某个实用程序中检查内部"应用程序版本(在应用程序运行期间)和外部"版本,该实用程序可以从其主要可执行模块加载程序集并读取/验证版本.

内部:
I think what you want to care about is not the file version but the version of the assembly implemented with the use of assembly executable modules (libraries and applications). Your versioning approach should be based of the versions of the assemblies and nothing else. For example, I try to support the system where all assemblies of the applications are maintained the way that all assemblies are recompilated with the exact same version of whole system or application. This part is totally on you.

You need to know how to check up version "inside" application (during your application run-time) and "outside", from some utility which can load assembly from its main executable module and read/verify the version.

Inside:
// currently running assembly:
System.Version executingVersion =
   System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

// entry assembly (normally, exe file):
System.Version entryAssemblyVersion =
   System.Reflection.Assembly.GetEntryAssembly().GetName().Version;



外面:



Outside:

System.Reflection.Assembly assembly = 
   System.Reflection.Assembly.LoadFrom(fileName);
System.Version version =
   assembly.GetName().Version;



根据此信息,您可以比较和验证版本.

有关更多信息,请参见:
http://msdn.microsoft.com/en-us/library/system.reflection. assembly.aspx [^ ],
http://msdn.microsoft.com/en-us/library/system.reflection. assemblyname.aspx [^ ],
http://msdn.microsoft.com/en-us/library/system.version.aspx [^ ].

除了程序集版本外,还有文件版本信息:



Based on this information you can compare and validate versions.

For more information, see:
http://msdn.microsoft.com/en-us/library/system.reflection.assembly.aspx[^],
http://msdn.microsoft.com/en-us/library/system.reflection.assemblyname.aspx[^],
http://msdn.microsoft.com/en-us/library/system.version.aspx[^].

In addition to assembly version, there is the file version information:

System.Diagnostics.FileVersionInfo version =
    System.Diagnostics.FileVersionInfo.GetVersionInfo(fileName);



文件版本和程序集版本可以不同.最好围绕程序集版本而不是文件版本构建版本控制策略.

—SA



File version and assembly version can be different. It''s the best to build versioning strategy around assembly versions, not file versions.

—SA


这篇关于检查文件是否与所用系统兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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