Getting assembly name

后端 未结 5 1876
灰色年华
灰色年华 2020-12-07 10:54

C#\'s exception class has a source property which is set to the name of the assembly by default.
Is there another way to get this exact string (without parsing a differe

相关标签:
5条回答
  • 2020-12-07 11:22

    You can use the AssemblyName class to get the assembly name, provided you have the full name for the assembly:

    AssemblyName.GetAssemblyName(Assembly.GetExecutingAssembly().FullName).Name
    

    or

    AssemblyName.GetAssemblyName(e.Source).Name
    

    MSDN Reference - AssemblyName Class

    0 讨论(0)
  • 2020-12-07 11:23
    System.Reflection.Assembly.GetExecutingAssembly().GetName().Name
    

    or

    typeof(Program).Assembly.GetName().Name;
    
    0 讨论(0)
  • 2020-12-07 11:23

    I use the Assembly to set the form's title as such:

    private String BuildFormTitle()
    {
        String AppName = System.Reflection.Assembly.GetEntryAssembly().GetName().Name;
        String FormTitle = String.Format("{0} {1} ({2})", 
                                         AppName, 
                                         Application.ProductName, 
                                         Application.ProductVersion);
        return FormTitle;
    }
    
    0 讨论(0)
  • 2020-12-07 11:25

    Assembly.GetExecutingAssembly().Location

    0 讨论(0)
  • 2020-12-07 11:44

    You could try this code which uses the System.Reflection.AssemblyTitleAttribute.Title property:

    ((AssemblyTitleAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyTitleAttribute), false)).Title;

    0 讨论(0)
提交回复
热议问题