Get name of assembly without version and other details

14.8k Views Asked by At

I am getting the name of an assembly as follows:

String fullName = Assembly.GetAssembly(typeof(CP.Proj.ILogger)).FullName;

And I get the following:

CP.Proj, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Is there a way to get only the assembly name "CP.Proj", without the version and other infos?

2

There are 2 best solutions below

0
giammin On BEST ANSWER

You need to get the AssemblyName object of that assembly through the Assembly.GetName() method

Assembly.GetAssembly(typeof(CP.Proj.ILogger)).GetName().Name

If the assembly is the one which is calling that method you can use:

string name = Assembly.GetCallingAssembly().GetName().Name;

or even create an utility method

public static string GetAssemblyShortName()
{
    return Assembly.GetCallingAssembly().GetName().Name;
}
0
zey On

Try this ,

**1**
System.Reflection.Assembly.GetExecutingAssembly().GetName().Name


**2**
typeof(Program).Assembly.GetName().Name;