Code Focused
Surfacing the Visual Basic Templates in WebMatrix
WebMatrix is an exciting new tool for creating ASP.NET Web applications. Unfortunately, Visual Basic developers face an additional challenge because Microsoft only surfaces C# templates. Here's how to get access to the VB templates.
I was fortunate enough to be present at the Microsoft's launch of WebMatrix at the 2011 CodeMash conference at the Kalahari Resort in Sandusky, Ohio on January 13, 2011. WebMatrix looked very exciting at the launch keynote and I was interested to see what it offers to the Visual Basic developer.
When you first launch WebMatrix 1.0 after installing it, you see a screen as shown in Figure 1.
[Click on image for larger view.] |
Figure 1. The opening screen of WebMatrix. |
Choosing the "Site From Template" option, you see the screen shown in Figure 2. Each of these templates are C# site templates.
WebMatrix supports Web site development in both C# and Visual Basic, so where are the Visual Basic templates? I expected to see a screen with templates for both languages. In this article, I demonstrate the steps needed to create the screen shown in Figure 3. This allows the creation of Visual Basic sites from templates as easily as C# sites, based on the site templates available from Microsoft at the time of this writing (March 2011).
If the C# templates are still Version 1.0 and you are just interested in installing the additional VB 1.0 templates, then download the code from this article's Web page and follow the directions in the ReadMe.txt file in the download. If the templates have been updated or new templates have been added, you may need to follow the steps in this article to create a new "Site From Template" page in order to include those new elements, especially to update the SHA1 checksums in the TemplateFeed.xml file in the Micrososft WebMatrix templates folder.
The Visual Basic templates were released later, on Monday February 7, 2011 as a NuGet package. NuGet is a Visual Studio extension that makes it easy to install and update open source libraries and tools.
Since NuGet is an extension, it must be run within WebMatrix or Visual Studio and does not appear in the computer's Start menu. In WebMatrix, it must run from the Administration page of a site as shown in Figure 4. I used the Starter Site template.
Selecting that option for the first time will lead to prompts to create a site administration password. Follow the prompts to create the site administration password. Log onto the site administration page with the newly created password and then search for "VB". You will see a page similar to Figure 5 that will allow you to download each of the VB site templates.
After installing each one, by default they will appear in the {My Documents}\My Web Sites\{Site Name}\Microsoft Templates\ folder. To use any of these templates to create Visual Basic sites, as provided by Microsoft, you have to create an "Empty Site" as shown in Figure 2. Then you must copy the contents of one of these Microsoft Templates folders to the root of the Empty Web site.
I know that WebMatrix is a v1.0 product, and I'm grateful that Visual Basic templates are available, but I can't help but think, "Give me a break. Are you serious Microsoft?" C# developers can simply pick a template from a main menu, but Visual Basic developers have to go through this much convoluted effort? No wonder Visual Basic developers sometimes feel like second-class citizens in the Microsoft ecology.
To create the screen shown in Figure 3, we have to accomplish the following tasks. They are more steps than I would like, but hopefully they are easy to follow. Note that Administrator access is required since it involves changes to the C:\Program Files\Microsoft WebMatrix\templates\ folder. If you are on a 64-bit version of Windows, that path would be C:\Program Files (x86)\Microsoft WebMatrix\templates\.
- Download the Visual Basic templates into a WebMatrix site.
- Create the same folder structure and metadata files as the C# templates.
- Create zip files from Step 2, with a VB suffix so they can later co-exist in the templates folder.
- Compute the SHA1 checksum for each of the VB template files.
- Modify the TemplateFeed.xml file in the Microsoft WebMatrix\templates folder to include the VB templates.
- Copy the updated VB template zip files and updated TemplateFeed.xml file into the WebMatrix\templates folder.
For Step 1, assuming you have been following along so far, it has been completed.
For Step 2, create a "temp" working folder where you have update rights. See Listing 1 for a complete directory listing of the results of Step 2 for reference.
Copy the Microsoft WebMatrix\templates folder into this temp folder. Copy the Microsoft Templates folder with the downloaded VB 1.0 templates into your temp folder. In the temp\Microsoft Templates folder, remove the spaces from the folder names and delete the License.rtf and README.txt files. You will have only four folders: BakeryVB, CalendarB, PhotoGalleryVB, StarterSiteVB.
Within each of those folders, create a folder named the same without the VB suffix and copy all the files into that folder. Example: you will have a temp\Microsoft Templates\BakeryVB\Bakery folder that contains all the files that were in temp\Microsoft Templates\BakeryVB folder.
Next extract the parameters.xml and manifest.xml files from the root of the corresponding C# template zip files and place them in the corresponding temp\Microsoft Templates\{site}VB\{site} folder. Example: temp\Microsoft Templates\BakeryVB\ folder will now have the parameters.xml and manifest.xml files from the \temp\templates\Bakery.zip file. You may find the open source 7-Zip utility available from 7-zip.org helpful in this and subsequent processes. See Listing 1 for a sample of the final folder/file structure.
For Step 3, create separate zip files of the contents of each of the temp\Microsoft Templates\{site}VB\ folders. Be sure to create the zip files such that the manifest.xml and parameters.xml and {site} folder are at the root of the zip file. Name these zip files the same as their parent folder with the zip extension. Example: temp\Microsoft Templates\BakeryVB\ will contain a BakeryVB.zip file that contains exactly the contents of the temp\Microsoft Templates\BakeryVB folder. See Listing 2 for a sample final result.
For Step 4, use the File Checksum Integrity Verifier (FCIV.exe) utility available from Microsoft here. Download and extract the fciv.exe utility and place in the C:\Windows folder so it can be available for use from any folder. Open a DOS Command window, navigate to the {My Documents}\temp folder and issue the following command:
fciv -add "Microsoft Templates" -r -type *.zip
Note the SHA1 values that are generated for each of the zip files you created.
For step 5, make a backup copy of the file TemplateFeed.xml file located in the temp\templates folder. Use notepad or your favorite editor to update the TemplateFeed.xml file with four new application sections, one for each of the VB template zip files. Simply copy the C# application section and modify the underlined locations as shown in the code below. The Code Download has the fully updated TemplateFeed.xml file for your reference.
<entry type="application">
<productId>BakeryVB</productId>
<title resourceName="Entry_BakeryVB_Title">Bakery VB</title>
<version>1.0</version>
<summary resourceName="Entry_BakeryVB_Summary">
Sample web site in VB showing a list of products that can be ordered.</summary>
<id>http://www.microsoft.com/web/webstack/bakery</id>
<updated>2010-3-24T18:30:02Z</updated>
<published>2010-03-24T18:30:02Z</published>
<longSummary resourceName="Entry_BakeryVB_LongSummary">
Sample web site in VB showing a list of products that can be ordered.</longSummary>
<link href="http://microsoft.com/web/webstack/bakery" />
<images>
<icon>http://go.microsoft.com/fwlink/?LinkId=195175</icon>
</images>
<keywords>
<keywordId>Templates</keywordId>
</keywords>
<author>
<name>Microsoft</name>
<uri>http://www.microsoft.com/</uri>
</author>
<installers>
<installer>
<id>1</id>
<languageId>en</languageId>
<installerFile>
<fileSize>50</fileSize>
<installerURL>file://%ProgramFiles%\Microsoft WebMatrix\templates\BakeryVB.zip</installerURL>
<sha1>d40bbb4eb23bda648a95c0841e7d762d57d6c372</sha1>
</installerFile>
<msDeploy />
</installer>
</installers>
</entry>
For Step 6, backup the existing TemplateFeed.xml file at {Program Files}\Microsoft WebMatrix\templates and overwrite it with your modified TemplateFeed.xml file. Also copy in the VB template zip files created in step 3. If all the steps were performed correctly, WebMatrix will show a screen similar to Figure 3 when "Site From Template" is selected.
Conclusion
Microsoft WebMatrix is an exciting product that makes the creation of custom ASP.NET Web sites possible without all the complexity of the full Visual Studio environment. Another advantage is the ability to easily leverage proven applications from the Web Gallery. WebMatrix also demonstrates Microsoft's commitment to open source by including PHP and MySQL applications in the Web Gallery.
Microsoft WebMatrix has great potential, but it is a version 1.0 release and it shows when it comes to Visual Basic template support. The steps needed to surface the Visual Basic templates in the Site From Template screen are overly complex. Microsoft should provide an independent installer package that integrates the Visual Basic site templates with a single command, so that both C# and Visual Basic templates are presented equally.
About the Author
Joe Kunk is a Microsoft MVP in Visual Basic, three-time president of the Greater Lansing User Group for .NET, and developer for Dart Container Corporation of Mason, Michigan. He's been developing software for over 30 years and has worked in the education, government, financial and manufacturing industries. Kunk's co-authored the book "Professional DevExpress ASP.NET Controls" (Wrox Programmer to Programmer, 2009). He can be reached via email at [email protected].