Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get name of assembly without version and other details [duplicate]

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?

like image 380
Miguel Moura Avatar asked Nov 06 '13 11:11

Miguel Moura


People also ask

How do I get a project assembly name?

If you know the assembly's file system path, you can call the static (C#) or Shared (Visual Basic) AssemblyName. GetAssemblyName method to get the fully qualified assembly name.

What is assembly GetExecutingAssembly ()?

Assembly property to get the currently executing assembly based on a type contained in that assembly. It also calls the GetExecutingAssembly method to show that it returns an Assembly object that represents the same assembly.

Where can I find DLL assembly name?

Open Visual Studio Go to Tools –> External Tools –> Add Title: Get Qualified Assembly Name Command: Powershell.exe Arguments: -command "[System. Reflection. AssemblyName]::GetAssemblyName(\"$(TargetPath)\"). FullName" Check "Use Output Window".

What is AssemblyName in C#?

An assembly's name is stored in metadata and has a significant impact on the assembly's scope and use by an application. A strong-named assembly has a fully qualified name that includes the assembly's name, culture, public key, version number, and, optionally, processor architecture.


2 Answers

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;
}
like image 99
giammin Avatar answered Oct 14 '22 01:10

giammin


Try this ,

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


**2**
typeof(Program).Assembly.GetName().Name;
like image 37
zey Avatar answered Oct 14 '22 01:10

zey