Will "the Mighty" Strohl

Modifying the Default DotNetNuke Module Templates

A great feature of DotNetNuke® is that each version comes with project templates for both the website, skins, and modules.  What is a project template?  Well, if you want to build your first module, then executing the project template inside of Visual Studio will give you a really great starting point, instead of having to figure out the files and file structure all on your own.  The project template puts all of that together for you.  All you have to do is give it a name, and then rename/change the code and files as you see fit.  (And then build your module of course.)

Any developer though has their own style of both creating the files and code within their user controls, and other related code files.  For example, you might have a specific namespace that you always like to work in, or you might always have specific properties that you create each time you build a user control.  Luckily, the project templates can be easily easily altered to remember the way you like to start with a module.

Where are the Project Templates?

I am not going to walk you through creating a new project template from scratch.  Instead, I will be showing you how to change a previously installed project template.  IN order to do that, you need to know where the template files are found.  They can be found at the following path:

C:\Documents and Settings\[Username]\My Documents\[Visual Studio Version]\Templates\ItemTemplates
C:\Documents and Settings\[Username]\My Documents\[Visual Studio Version]\Templates\ProjectTemplates

The Item templates are where you’ll find the simple module and skin templates.  The Project templates is where you’ll find the DNN website template, and the compiled module template.  At this time, module templates only are available for VB, and not C#.

What are the Templates?

The templates themselves are zip files, named as follows (the availability of the templates below will vary, depending on the DNN StarterKit(s) you have installed):

  • Module_VB.zip – This is a WSP version of a module template that has a DAL.
  • Simple_VB.zip – This is as WSP version of a module template that does not have a DAL
  • Skin.zip – This is a skin package template
  • Module_Compiled_VB.zip – This is a VB version of a WAP module
  • Module_Compiled_CS.zip – This is a C# version of a WAP module
  • DotNetNuke.zip – This is the DNN website template, which gets you started on a working instance of DNN

If you extract the contents of one of those archives into a folder, you will see a familiar folder structure for the Module_VB and Module_Simple templates (that is, if you’ve ever looked at the file system for a DNN instance.  The compiled versions will look much different, and since they are much more complicated for this type of article, I will focus on the WSP modules.

Before you modify the default templates, I would suggest saving a copy of them to help you restore them later, if necessary.  Additionally, it would be a good idea to just work out of your own archive and files, resulting in you generating your own template.

Modifying the Templates

Modifying the templates is easier than you might imagine.  Since they are just archives, it literally can be as simple as extracting the files, changing them, and putting them back into the original archive.  Modifications will need to be made in one or more of the following places.  The most important place to make a change, is in the .vstemplate file.  Even though it does not have the XML extension, it is just an XML file.  Open it with your favorite text editor.

Most of the XML should be self-explanatory, if you understand XML.  In fact, it carries several similarities to the DNN manifest file.  For example, it allows you define the template name, folders, and files, much like the DNN manifest does for a module.  Here is a quick run-down of the XML elements you need to know.

  • DefaultName – This is the name that Visual Studio will use to name your folders, when created. This is used due to a limitation in the templating system.
  • Name – This is the name that you wish to show up in the dialog that appears when Visual Studio reads and loads the templates.  This happens when the New Item or New Project dialogs are opened.
  • Description – This is mostly necessary for yourself, but does appear as a tooltip in the Visual Studio IDE.
  • ProjectType and ProjectSubType – These values are mainly used for the folder structure within the templates directory.  I suggest you leave them alone, unless you really know what you’re doing.
  • Icon – This names the icon file that needs to be in the root of the template archive.  If you wish to have something other than the DNN icon, put it in the root of the archive, and then name it here.
  • Folder – This node names and then defines the folder(s), and the subsequent files that should be put into those folders.  A Folder element can have another child element of the same name.
  • ProjectItem – This element allows you to define a file within a folder.  Using the $fileinputname$ parameter, you can customize the file name, as you will see with the DNN manifest file.

Now that you know what the elements are, and how they are used, we can concentrate on the things that you really want to worry about, the code files.

Modifying the Template Code Files

If you open any of the class files, you will immediately see a familiar parameter from the previous step, namely $fileinputname$.  This allows you to customize things like class names, namespaces, property names, and so on.  Simply insert the parameter into your code files where you would like it to be replaced with the name value entered by the person creating the project in the Visual Studio New Item dialog.

You should now continue to alter the code as you see fit.  For example, changing the namespaces to match yours, adding namespaces, and so on.  Once you do, simply save the file and place it into your template archive.  If you add any new files or folders, do so but make sure that you add the folder and files to the .vstemplate configuration file.

Deploying the Template

Deploying the template is extremely easy, though I am not telling you the standard way.  Instead, I am going to tell you the easy way.

Hopefully, you have created a copy of the template archive, and renamed it to something more meaningful to you.  After doing so, save a new copy of the archive into the same directory that you pulled the original archive out of.  That’s it!  Nothing messy here.  You don’t need to unzip it or anything.  Visual Studio will do the rest of the work for you.

blog comments powered by Disqus