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.
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#.
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):
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 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.
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.
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.