How to Get Public Key for SharePoint Projects

Visual Studio Version: 2010

SharePoint Foundation development projects often involve a mixture of imperative coding and XML markup. Frequently, you add your new assembly’s Public Key Token to a project file, such as an XML configuration file.

If your Visual Studio project is based on any of the SharePoint 2010 project templates in Visual Studio, you can simply insert the placeholder $SharePoint.Project.AssemblyPublicKeyToken$ where the Public Key Token should be in most kinds of project files (but not .cs or .vb files or other compilable files).

When you build and deploy the project, Visual Studio will replace the placeholder with the Public Key Token in the copies of the files that are actually deployed.

If you need to insert the Public Key Token in a file that does not support the placeholders, you will need a way to obtain the Public Key Token. This topic explains how to add an item to the Visual Studio Tools menu that can be used to obtain the Public Key Token of an assembly under development.

  • Launch Visual Studio and click on External Tools under Tools Menu as shown below:

1

  • Click on Add button

2

  • Enter Title of your choice
  • Enter Command as the path to sn.exe file, you can find this command line utility at the following location C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\x64\sn.exe
  • Enter Arguments as -T $(TargetPath), this will be replaced by the selected project later on

Make sure “Use Output Window” checkbox is checked so that you can be able to get the Public Key on the Output Window with in Visual Studio.

3

  • Select the project for which you want to find out the Public Key

4

  • Click on Get Public Key under Tools menu

5

  • Public Key Token is now available on the output window

6

That’s so simple yet powerful.

It is really useful for a SharePoint Developer to have these kind of tools handy.

Hope this will help someone in need…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s