我怎样才能得到执行的程序集的版本? [英] How can I get the executing assembly version?

查看:113
本文介绍了我怎样才能得到执行的程序集的版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用下面的代码来获取使用C#3.0中执行的程序集的版本:

I am trying to get the executing assembly version in C# 3.0 using the following code:

var assemblyFullName = Assembly.GetExecutingAssembly().FullName;
var version = assemblyFullName .Split(',')[1].Split('=')[1];

是否有这样做的另一种适当的方式?

Is there another proper way of doing so?

推荐答案

有两个选项...无论应用程序类型你可以随时调用的:

Two options... regardless of application type you can always invoke:

Assembly.GetExecutingAssembly().GetName().Version

如果一个的Windows形式应用程序,您可以通过应用始终可以访问,如果专门针对产品版本好看。

If a Windows Forms application, you can always access via application if looking specifically for product version.

Application.ProductVersion

使用 GetExecutingAssembly 程序集的引用并不总是一个选项。因此,我个人觉得有用创造项目静态辅助类,我可能需要引用底层的组装或装配的版本:

Using GetExecutingAssembly for an assembly reference is not always an option. As such, I personally find it useful to create a static helper class in projects where I may need to reference the underlying assembly or assembly version:

// A sample assembly reference class that would exist in the `Core` project.
public static class CoreAssembly
{
    public static readonly Assembly Reference = typeof(CoreAssembly).Assembly;
    public static readonly Version Version = Reference.GetName().Version;
}



然后,我可以清晰地引用 CoreAssembly.Version 根据需要在我的代码。

Then I can cleanly reference CoreAssembly.Version in my code as required.

这篇关于我怎样才能得到执行的程序集的版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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