A place for me to keep track of hard to find information related to the use of Microsoft Visual Studio, System Center and SharePoint products.

Monday, April 26, 2010

SharePoint assemblies and the GAC

One of the more tedious aspects of SharePoint feature development is that the feature receiver must be installed into the Global Assembly Cache. Because of this, the dll has to be strongly named and referenced by its four-part assembly name within the Feature.xml file. The first three parts (name, version, and culture) are pretty easy to figure out. But the last part, the public key token, is not so obvious.

In my opinion, the most elegant way to discover this information is to use the Strong Name tool (sn.exe) provided in Visual Studio (see Wriju's blog entry on this http://blogs.msdn.com/wriju/archive/2008/07/01/how-to-find-public-key-token-for-a-net-dll-or-assembly.aspx).

Not to be outdone, and being a generally lazy guy, I set out to find a way to make this process even easier. So I created a new External Tool command in Visual Studio that runs sn.exe and gets the public key token of an assembly for me and displays it in the IDE's Output window:

In Tools
External Tools, click the add button.

For title, call it something like 'Get &Public Key Token' (for you non win forms developers, the ampersand creates a keyboard shortcut for the command).

In command, enter 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\sn.exe' (you may need to modify the path depending on where you have sn.exe installed).

For arguments, enter '-Tp $(TargetPath)'. This ensures that the correct assembly is checked, based on build configuration. Ensure 'Use Output window' is checked. And that's it. Of course, the assembly needs to be signed and you need to build the dll before running this command.

No comments:

Post a Comment

Followers