Tuesday, February 13, 2007

Installing Your Program - Part 1 - Signing Your Assembly.

This is the first part of my little review on writing an installer to get your MCML program into Media Center.

The code part of your Media Center program (usually written in C#) is installed into the Global Assembly Cache (GAC) of Windows. The GAC is used to store .NET assemblies that are shared across multiple programs. Your basic Windows forms classes etc. all live in the GAC.

Before any program can be added to the cache, it must be strongly named. A strongly named assembly has a public and private key associated with it, to ensure that it is actually the original class and not a modified or doctored version.

To generate this key, you will need to use the 'SN' command that ships with Visual Studio. You will find it in <Visual Studio Install Directory>/SDK/v2.0/BIN

Use 'cmd' (the command-line interpreter) or even better, open the command prompt from the start menu, under 'Programs|Visual Studio 2005' so you won't need to bother with your path information.

Type 'sn -k <filename>.snk' to generate a new key file.

Then in Visual Studio, right click on your project in the project view and choose 'Properties' from the drop-down menu that will appear. Under 'signing' you will have the option of choosing a key file. Choose the one you created with the SN utility, and rebuild your project.

There! You have a signed assembly, ready for installation into the GAC.

No comments: