OK, now there are interesting problems when installing an application for Media Center, because there are two different ways of registering your application.
To appear in Media Center, several entries need to be made to the Windows Registry.
In the first release of the Windows Media Center SDK (and in previous versions, such as Windows XP Media Center Edition) Microsoft suggested that you could either create entries into the registry yourself, located under the registry key..
Local Machine\Software\Microsoft\Windows\CurrentVersion\Media Center\Extensibility
Personally, I like this technique. But there are two drawbacks.
1. Charlie, the Microsoft product director for Media Center extensibility (IE. the Media Center SDK) has informed me that MS won't guarantee that the method of registering plugins will remain the same. Of course, I then asked 'OK - then why do you TELL us to register them that way?' and there wasn't much of a response. I'm yet to see if this is still true in the newer version of the Media Center SDK.
2. If you run a 32 bit installation on a 64 bit version of Windows, your registry entries are placed in an entirely different tree. So the 64 bit version of Media Center can't actually see the keys you've created.. This means you MUST produce both a 64 and 32 bit version of your installer.
Microsoft themselves suggest you use WiX, which is an open source product of theirs that allows you to create installers - but since it's a complicated platform and I want to be able to take you through the basics without needing any additional software, I'm going to take you through the easy, but perhaps not officially supported method of adding registry keys directly.
SO - let's take a look at our installer.
The first thing we need to do is add our program to the Global Assembly Cache. The GAC is a lot like copying a DLL file into the Windows/System directory - it creates a single assembly that you can share among your various applications. It allows Media Center to find your C# classes and code.
This has already been done in the copy of the installer from our last version of TriviaCenter.
Next up, we need to set up our registry entries.
A Media Center application needs at least two GUID's (Globally Unique IDentifiers). The first one is the GUID for the application as a whole (for instance, TriviaCenter) while the second is for an entry point into the application.
An entry point is basically a visible button that a user can press to access your program. A single application can have a number of entry points. For example, MoreWithMyMusic (a program of mine) has a single Application GUID, but it has TWO buttons that appear in the More Programs list - one to normalise all of your music, with a second one to search for Ultrastar songs.
TriviaCenter is very simple. We only need one entry point. So use GUIDGEN (you can often find this tool in the 'Tools' menu of Visual Studio) to build ourselves a new Application and Entry Point GUID.
In our example, I picked {D0515079-4F80-4970-93D5-02F5CF736444} for the app, and {396E0EB3-BC22-4cb2-A6CB-954B5F7CF444} for the entry point.
So at the end of the day, our registry should look like this...
...\Windows\CurrentVersion\Media Center\Extensibility
Applications
{Our Application GUID}
Title (String) "TriviaCenter"
Entry Points
{Our Entry Point GUID}
Title (String) "TriviaCenter"
Description (String) "Sample Code by Steven Harding"
AppID (String) "Our Application GUID"
Timestamp (Integer) Random Numbers - They Don't Really Matter
Addin (String) "The complete path of your addin"
ImageURL "The Path to our Image File"
In the above list, bold text represents registry KEYS, while non-bold text represents registry VALUES.
So now that we know the GUIDS that we need, all we really need to throw together are two things - we need to create an image file or logo that should appear in our list of Media Center games, and we also need to discover what the path of our C# assembly is supposed to be.
To make the full path for your assembly, you need a few parts. The first part is the
<Name of the AddInModule class> , <Full Name of the Assembly>
For example, the full path to the MCMLookalike sample addin is...
MCMLookalike,MCMLookalike,Culture=Neutral,Version=0.0.1000.0,PublicKeyToken=aadbb711d5721433
Because an assembly that is in the Global Assembly Cache can have many versions, you need to do more than just select the assembly by name. This method, with specifying culture, version and a key token allows you to be secure in the fact that the version of the assembly you expected is the version you are getting.
So how do we figure out this address for TriviaCenter?
Media Center applications all start from the same point - a class that is based on 'IAddInModule' and 'IAddInEntryPoint'. If you check out the source code in 'AddIn.cs', you will find that we already have a class like that. It's name is 'BaseAddin'.
public
void Launch(AddInHost host)
{
Host = host;
s_session =
new HistoryOrientedPageSession();
s_session.GoToPage(
"resx://TriviaCenter/TriviaCenter.Resources/Default");
}
If you follow the code down for a while, you will find that there's a method called 'Launch'. All it does is creates a new 'HistoryOrientedPageSession' object, and calls 'GoToPage' to open our first MCML file.
But OOPS - we don't HAVE an MCML file called 'Default' anymore. Let's fix this and change the path to this one...
s_session.GoToPage("resx://TriviaCenter/TriviaCenter.Resources/StartPage");
The HistoryOrientedPageSession class allows Media Center to remember the 'history' of your application, meaning that when you press 'Back', you will return to the MCML file you were in previously.
The BaseAddin class is in the namespace 'TriviaCenter'.
So - we now know how to start our path - it's
TriviaCenter.BaseAddin , <Full Name of the Assembly>
How do we get the full name? Well there are a few command line tricks you can do, but I find it easier to cheat a little.
As part of our compile we are already adding TriviaCenter to the Global Assembly Cache. So if we check the cache, it will already have all of the information we need.
Go to 'Start | Run' and check out %WINDIR%/Assembly

This is the folder where all of the files in your Global Assembly Cache are kept. All you need to do is scroll down from the top and find yourself 'TriviaCenter'. If you hover your mouse over the file (or right-click it and choose 'Properties') you will find the full name for the assembly.
TriviaCenter,Culture=Neutral,Version=0.0.1000.0,PublicKeyToken=aadbb711d5721433
And there we go - all done. Our complete path is...
TriviaCenter.BaseAddin ,TriviaCenter,Culture=Neutral,Version=0.0.1000.0,PublicKeyToken=aadbb711d5721433
The last thing is to associate this entry point with a part of Media Center. If you've ever played in 'More Programs', you will have noticed that you have different categories, such as Games, Music, TV etc.
The SDK gives a good list of your options here. To associate our addin with one of these places, you simply create a key under the section that you want. For example, to register our app under 'More Programs', you can simply create it under..
.../Media Center/Extensibility/Categories/More Programs/Entry Point GUID
AppID (String) "GUID of Application"
To register it as a game, we add a key with the entry point GUID under
../Media Center/Extensibility/Services/Games/Entry Point GUID
AppID (String) "GUID of Application"
And all of the rest is kinda straight-forward. I'm not going to go into details of how to use the setup system here - all you really have to do is go through, give the thing a new ProductCode and UpgradeCode, change 'MCMLookalike' to 'TriviaCenter' and generally play around.
Then change your build configuration from 'Debug' to 'Release' and compile. It will create a setup file for you.
For the updated code & installer, download this