This is the first part in a series of tutorials aimed at guiding novice developers though building a "Hello World" Windows Home Server Add-In, using only freely-available tools (including Visual Studio Express).
One of the major barriers for beginning developers creating Add-Ins is that the initial setup and configuration of the development environment is fairly convoluted; you need to bring together quite a few components to even make a start. Because of this, Part 1 of our tutorial guides you through the installation and configuration of Visual Studio Express, with some Windows Home Server-specific steps.
It's not glamorous, but it needs to be done!
I'm going to assume you're working with Windows XP, but Windows Vista setup should be basically identical to the steps outlined below.
For this tutorial, we're building a Windows Home Server Add-In that detects changes to Shared Folder permissions. You can access the other parts of the tutorial, or download the code I'm using in the screenshots, using the links below.
- Part 1: Installing and configuring your development environment
- Part 2: Designing a GUI and initial deployment test
- Part 3: Responding to Windows Home Server Notifications (code)
- Part 4: Using FancyListView and comparing permissions (code)
- Part 5: Building an installer package using WiX (code)
Step 1: Downloading and Installing Visual Studio Express
Jump over to http://www.microsoft.com/express/download/ and download Visual Studio Express for C#. You want the Web Install, so just click Download.
The installer will pull down all of the various packages you need, install them, and then prompt you to restart your computer. Once you've restarted, Visual Studio will finish up the installation.
Step 2: Running Visual Studio Express for the first time
Visual Studio Express will spend some time setting up your initial environment. Once loaded, you'll want to register the software so it doesn't expire on you in 30 days. From the Help menu, select Register Product.
Click the Register Now link, sign in with a Windows Live ID, and complete the registration form.
Copy the registration code into Visual Studio and click Complete Registration.
Step 3: Download and Install WiX
WiX is a great framework for building MSI packages. You'll need to package your code as an MSI, and customize some settings, in order for Windows Home Server to see it as a valid Add-In to install.
Browse to http://wix.sourceforge.net/ and hit the Weekly Releases section (http://wix.sourceforge.net/releases/).
WiX 3.0 is alpha code, but it's the best option for us at the moment. I've been using WiX 3.0 weekly releases to build my production installers for WHS Disk Management from the start, and it's been rock solid for me.
Navigate to the latest build number, download Wix3.msi and install it.
WiX will complain that you're using Visual Studio Express, but that's expected. WiX won't allow us to use the fancy GUI tools to build packages in Visual Studio Express, but we'll still get command line options. And everyone loves the command line.
Step 4: Referencing the Windows Home Server libraries
In order to write code that references Windows Home Server, we need access to the WHS libraries. These will be referenced by Visual Studio, and will allow us to use all the cool WHS GUI bits.
We'll grab these files off our server.
Click Start, Run, type mstsc -console, and then click OK. Enter the name of your server, click the Options button, navigate to the Local Resources tab and then click More. Check the box next to Drives, then click OK.
We're doing this so we can copy and paste files back and forth between our development machine and our server.
Click Connect, and then enter your server's Administrator username and password.
Navigate to C:\Program Files\Windows Home Server\. You now want to select all the Application Extension files; the easiest way to do this is to sort by Type.
I've left off the Xceed libraries here; they're what the console uses to display various charts and graphs, and we don't have a license to use those libraries.
Copy the files (CTRL-C), minimize the Remote Desktop session, and then paste the files (CTRL-V) into a folder on your computer. I've stuck the files in a subfolder of the My Documents\Visual Studio 2008\ folder, but you can put them anywhere.
Brendan Grant has blogged this part of the tutorial already, but I'm including it here for completeness.
Once you've copied the Windows Home Server libraries to your local machine, we need to add a registry entry to tell Visual Studio where to find them. When you add references in Visual Studio, you can manually navigate to the appropriate library, but that gets old fast. This way is easier.
Open regedit and navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v2.0.50727\AssemblyFoldersEx. Right-click AssemblyFoldersEx and create a new Key.
Call the new key Windows Home Server. Modify the Default entry for your new key, and enter the path to the library files we copied earlier. Click OK to save the path, and then close regedit.
Step 5: Adding Windows Home Server controls to the Visual Studio Toolbox
Building Windows Forms applications is always easier when you can use the Visual Studio Designer to drag and drop controls and components. We'll add the Windows Home Server controls to a new Toolbox tab so we can drop them into our Add-In as needed.
Open Visual Studio, and display the Toolbox using the View menu. Right-click the Toolbox, and choose Add Tab.
Name your new tab Windows Home Server, then right-click the tab and select Choose Items.
You'll be presented with a window from which you can select various controls. Click the Browse button and navigate to the folder where you saved the Windows Home Server libraries. Select homeservercontrols.dll and click Open.
Don't touch anything!
All the Windows Home Server controls loaded from homeservercontrols.dll are highlighted, and you don't want to manually go back through that list clicking them all. Just press the space bar once, and they'll all be checked, then click OK.
Step 6: Installing Brendan's Add-In Templates
This is the last step for this part of the tutorial.
Download Brendan's C# templates (http://ihatelinux.blogspot.com/2007/11/whs-developer-tip-4-project-templates.html) and save the zip file to My Documents\Visual Studio 2008\Templates\Project Templates\Visual C#\.
Now reopen Visual Studio and choose File --> New --> Project. You'll see Home Server Add-In as an available template.
Your development environment is now ready to begin work on an Add-In. Next time, we'll create a new Add-In from Brendan's template and actually display something in the Windows Home Server Console.
(If you can't wait until then, and decide to go diving in without me, make sure to retarget the project to .NET 2.0; Visual Studio 2008 defaults to .NET 3.5, which isn't installed by default on Windows Home Server.)
Edit: Thanks to Chris and Kevin for pointing out that you just need to save the zip file to the templates folder; extracting the contents of the zip won't work.