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?
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.
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.
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".
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.
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;
}
Try this ,
**1**
System.Reflection.Assembly.GetExecutingAssembly().GetName().Name
**2**
typeof(Program).Assembly.GetName().Name;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With