Monday, March 29, 2010

Create a Tool to Get the Full Name of an Assembly

Title: Create a Tool to Get the Full Name of an Assembly

Details: Here is a wonderful way to create a tool to get the full name of an assembly provided by Microsoft ( original link ). Create a command line project and name it as GetAssemblyName using the below code. Below are few screenshots how it looks like ( output ) after you create it.

#1 Adding the tool to the External Tools on your Visual Studio 2010
tools
#2 Linking the Tool
link
#3 Using the tool and output
output

Code:

using System;
using System.Reflection;
using System.IO;

namespace GetAssemblyName
{
class Program
{
static void PrintUsage()
{
Console.WriteLine("Usage: GetAssemblyName.exe \n");
Console.WriteLine(@"Example: GetAssemblyName.exe C:\MyAssembly.dll");
Console.Read();
}

static void Main(string[] args)
{
if (args.Length < 1 || args[0] == "?")
{
PrintUsage();
return;
}

string filename = args[0];

try
{
AssemblyName an = AssemblyName.GetAssemblyName(filename);
Console.WriteLine("Fully specified assembly name:\n");
Console.WriteLine(an.ToString());
}
catch (FileNotFoundException)
{
Console.WriteLine("Cannot locate the assembly. Check the path and try again.");
}

Console.Read();
}
}
}



To add a Get Assembly Full Name item to the Tools menu





  • In Visual Studio, select External Tools from the Tools menu.


  • In the External Tools dialog, click Add and enter Get Assembly Full Name for the Title.


  • Fill the Command textbox by browsing to GetAssemblyName.exe.


  • In the Arguments textbox, type the following (which is case sensitive): $(TargetPath)


  • Enable the Use Output window checkbox. Click OK.


  • The new command is added to the Tools menu.



Technorati Tags: ,

1 comment:

Sandeep K Nahta said...

Another way to get the same result
http://snahta.blogspot.com/2008/12/public-token-key-for-assembly.html

I think there is yet another way using Reflector also ...

Just in case you want to avoid writing code :)