Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
389 views
in Technique[技术] by (71.8m points)

c# - 如何获取程序集文件版本(How can I get the assembly file version)

In AssemblyInfo there are two assembly versions:

(在AssemblyInfo ,有两个程序集版本:)

  1. AssemblyVersion : Specify the version of the assembly being attributed.

    (AssemblyVersion :指定要赋予属性的部件的版本。)

  2. AssemblyFileVersion : Instructs a compiler to use a specific version number for the Win32 file version resource.

    (AssemblyFileVersion :指示编译器对Win32文件版本资源使用特定的版本号。)

    The Win32 file version is not required to be the same as the assembly's version number.

    (Win32文件版本不需要与程序集的版本号相同。)

I can get the Assembly Version with the following line of code:

(我可以使用以下代码行获取Assembly Version :)

Version version = Assembly.GetEntryAssembly().GetName().Version;

But how can I get the Assembly File Version ?

(但是,如何获取Assembly File Version ?)

  ask by Enyra translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

See my comment above asking for clarification on what you really want.

(请参阅上面的我的评论,要求澄清您真正想要的内容。)

Hopefully this is it:

(希望是这样:)

System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fvi.FileVersion;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...