最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How to get the product version of a DLL as an int64 - Stack Overflow

programmeradmin1浏览0评论

I am trying to get the product version of a DLL.

public void CheckApi(string apiName, ref Int64 apiVersion)
{
  string version = FileVersionInfo.GetVersionInfo(apiName).FileVersion!;
}

This does work, but it gets the version as a string. I want the function to return the product version as an int64 to the caller in apiVersion. With an int64 it is then very easy to compare the version returned to see if it meets the minimum version required for the program.

So for example if the product version is "10.0.1904.5072" I want it to return

0x000A0000077013D0 (000A 0000 0770 13D0)

I'm certain that it is possible to parse the string and do a hard conversion, but is there another better way to get the product version of the DLL as an int64.

I am trying to get the product version of a DLL.

public void CheckApi(string apiName, ref Int64 apiVersion)
{
  string version = FileVersionInfo.GetVersionInfo(apiName).FileVersion!;
}

This does work, but it gets the version as a string. I want the function to return the product version as an int64 to the caller in apiVersion. With an int64 it is then very easy to compare the version returned to see if it meets the minimum version required for the program.

So for example if the product version is "10.0.1904.5072" I want it to return

0x000A0000077013D0 (000A 0000 0770 13D0)

I'm certain that it is possible to parse the string and do a hard conversion, but is there another better way to get the product version of the DLL as an int64.

Share Improve this question edited Apr 1 at 20:03 James Z 12.3k10 gold badges27 silver badges47 bronze badges asked Apr 1 at 19:31 GaryGary 871 silver badge9 bronze badges 1
  • 5 FileVersionInfo provides four properties for the four parts already: FileMajorPart, FileMinorPart, FileBuildPart, FilePrivatePart. So you don't need to parse anything - just shift each part appropriately and OR them together. – Jon Skeet Commented Apr 1 at 19:56
Add a comment  | 

1 Answer 1

Reset to default 0

Thank you Jon. That was very helpful.

public void CheckApi(string apiName, ref Int64 apiVersion)
{
  Int64 v1 = FileVersionInfo.GetVersionInfo(apiName).FileMajorPart;
  Int64 v2 = FileVersionInfo.GetVersionInfo(apiName).FileMinorPart;
  Int64 v3 = FileVersionInfo.GetVersionInfo(apiName).FileBuildPart;
  Int64 v4 = FileVersionInfo.GetVersionInfo(apiName).FilePrivatePart;

  apiVersion = (v1 << 48) | (v2 << 32) | (v3 << 16) | v4;
}

This returns the File Version which for my purposes will always be the same as the Product Version. For anyone who really needs the Product Version there are also four properties to get that info ProductMajorPart, ProductMinorPart, ProductBuildPart, and ProductPrivatePart.

发布评论

评论列表(0)

  1. 暂无评论