SharePoint Productivity Tip of the day

Posted on 12/6/2009 @ 5:01 PM in #SharePoint by | Feedback | 6064 views

This tip will make it easy for you to get that assembly name right within Visual Studio.
This applies to both SP2010 and SP2007.

  1. In Visual Studio, Go to Tools –>  External Tools.
  2. Click on “Add” to add a tool, and put in the following values:
    1. Title: S&trong Name
    2. Command: Powershell.exe
    3. Arguments: -command "[System.Reflection.AssemblyName]::GetAssemblyName(\"$(TargetPath)\").FullName"
    4. Check “Use Output Window”
    5. Uncheck everything else – here’s how it should look -

3. That’s it, now in your project, Visit Tools –> Strong Name, and in the output window, itwill give you the assembly name like this –>

SandBoxWebPartWithProxy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=64b818b3ff69ccfa

Sound off but keep it civil:

Older comments..


On 12/6/2009 10:29:54 PM Harish Mathanan said ..
Nice tip! thanks Sahil :)


On 2/23/2010 1:02:43 AM Venkatesh said ..
Hi,


In the command, when i give "Powershell.exe", I am getting error as "Command is not a valid executable".. How to correct this?


Thank you


On 7/18/2010 1:44:55 PM Andrew Vevers said ..
Hello

I am getting the error:

Exception calling "GetAssemblyName" with "1" argument(s): "The path is not of a


legal form."


At line:1 char:50


+ [System.Reflection.AssemblyName]::GetAssemblyName <<<< ("").FullName


+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException


+ FullyQualifiedErrorId : DotNetMethodException

- any ideas?


Am using it against a SharePoint 2010 solution.

Regards

Andrew


On 7/18/2010 10:12:12 PM Sahil Malik said ..
Is your project built yet Andrew?


On 8/13/2010 6:42:05 AM Vivek Soni said ..
Thanks Sahil for this nice tip!


On 9/9/2010 1:56:44 PM David said ..
Thank you!! This tip just saved my first production Sharepoint 2010 box from getting airborne ;-)


On 1/12/2011 1:22:18 PM David Smith said ..
I had the same error as Andrew . I had to restart VS2010.


On 1/24/2011 3:50:45 PM Nimesh said ..
Getting the following error when try to use the StrongName option for a WCF service

Exception calling "GetAssemblyName" with "1" argument(s): "Could not load file


or assembly 'C:\Users\nmarker\Documents\Visual Studio 2010\Projects\CPUMonitor\


CPUMonSVCLib\obj\Debug\CPUMonSVCLib.dll' or one of its dependencies. This assem


bly is built by a runtime newer than the currently loaded runtime and cannot be


loaded."


At line:1 char:50


+ [System.Reflection.AssemblyName]::GetAssemblyName <<<< ("C:\Users\nmarker\Doc


uments\Visual Studio 2010\Projects\CPUMonitor\CPUMonSVCLib\obj\Debug\CPUMonSVCL


ib.dll").FullName


+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException


+ FullyQualifiedErrorId : DotNetMethodException

Any thoughts?


On 12/7/2011 10:58:40 AM Stephen said ..
I kept getting errors. Make sure you ar ebuilding against .Net 3.5 and not 4!


On 6/25/2012 2:14:29 PM Sankalp said ..
Great Tip


On 8/28/2012 11:36:03 AM Jesse said ..
Hi, what exactly do we need to put on the path: (\"$(TargetPath)

I'm getting an Exception calling "GetAssemblyName" with "1" Argument: "Could not load file or assembly.

Thanks,


On 9/24/2012 4:30:09 PM Nemo said ..
Hi,

I get this error when I tried the above method. Any suggestion to what needs to be corrected? I m using .net 3.5 framework against SP 2010. Any help is greatly appreciated. TIA.

Exception calling "GetAssemblyName" with "1" argument(s): "Could not load file


or assembly 'C:\Users\abcd\Documents\Visual Studio 2010\Projects\WebServiceD


emo\WebServiceDemo\obj\Debug\WebServiceDemo.dll' or one of its dependencies. Th


e system cannot find the file specified."


At line:1 char:50


+ [System.Reflection.AssemblyName]::GetAssemblyName <<<< ("C:\Users\abcd\Doc


uments\Visual Studio 2010\Projects\WebServiceDemo\WebServiceDemo\obj\Debug\WebS


erviceDemo.dll").FullName


+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException


+ FullyQualifiedErrorId : DotNetMethodException


On 10/10/2012 7:20:41 AM Karlos said ..
for folks who are getting the above error:

MAKE SURE TO DEBUG YOUR PROJECT FOR THE FIRST TIME before using this custom tool. When you debug your project a .dll will be deployed in your project destination for the first time.

You can then use the tool as described by Sahil. At least it worked for me.


On 4/8/2013 8:13:56 AM MarwenK said ..
Thanks Man !