How can I get the executing assembly version?

前端 未结 6 1570
慢半拍i
慢半拍i 2020-12-07 13:51

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

var assemblyFullName = Assembly.GetExecutingAssembly().FullName;
var ve         


        
6条回答
  •  温柔的废话
    2020-12-07 14:14

    In MSDN, Assembly.GetExecutingAssembly Method, is remark about method "getexecutingassembly", that for performance reasons, you should call this method only when you do not know at design time what assembly is currently executing.

    The recommended way to retrieve an Assembly object that represents the current assembly is to use the Type.Assembly property of a type found in the assembly.

    The following example illustrates:

    using System;
    using System.Reflection;
    
    public class Example
    {
        public static void Main()
        {
            Console.WriteLine("The version of the currently executing assembly is: {0}",
                              typeof(Example).Assembly.GetName().Version);
        }
    }
    
    /* This example produces output similar to the following:
       The version of the currently executing assembly is: 1.1.0.0
    

    Of course this is very similar to the answer with helper class "public static class CoreAssembly", but, if you know at least one type of executing assembly, it isn't mandatory to create a helper class, and it saves your time.

提交回复
热议问题