This is not a difficult task. We can add whatever
Imports to our template file, so that it will reflect in the projects. A modified Form is given with this article. For other projects also, you can easily modify the appropriate file and add a small piece of code to do it. All the template files can be found in %VS.Net Installation dir%\Vb7\VBWizards.
For example, you can add:
on top of the template file and get this in your project.
Here, I came up with a decision that the namespace will be as the assembly name. I came to this decision because of their Root Namespace concept. If we have the same thing in our class, then the namespace will be %RootNamespace%.RootNamespace%. This is surely not what we want to do. So, we must make a decision to define the namespace.
To make this happen to Windows Forms, we must do few changes. Here, I'll only change the Windows form template. Others you can follow the same way and do it easily.
Namespace [!output SAFE_NAMESPACE_NAME]
This variable is defined in the script file such that it will refer to the assembly name. You can change this as you want.
AddFileToVSProject(strItemName, selProj, selObj, strTemplateFile, bValidate) in common.js.
Also, I must change default.js. Because of my change in the namespace now, the startup object is changed. So, I must change that file also.
Samples provided with this article are for Windows Application template. But you can easily modify your other templates and get these features.
Make backup of your:
- %VS.Net Installation dir%\Vb7\VBWizards\1033\common.js
(E.g.: C:\Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBWizards\1033\common.js)
- %VS.Net Installation dir%\Vb7\VBWizards\WindowsApplication\Scripts\1033\default.js
(E.g.: C:\Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBWizards\WindowsApplication\ Scripts\1033\default.js)
- %VS.Net Installation dir%\Vb7\VBWizards\WindowsApplication\Templates\1033\Form.vb
(E.g.: C:\Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBWizards\WindowsApplication\ Templates\1033\Form.vb)
- %VS.Net Installation dir%\Vb7\VBWizards\WinForm\Templates\1033\Form.vb
(E.g.: C:\Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBWizards\WinForm\ Templates\1033\Form.vb)
- %VS.Net Installation dir%\Vb7\VBWizards\Class\Templates\1033\Class.vb
(E.g.: C:\Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBWizards\Class\ Templates\1033\Class.vb)
And replace those with the files which come with this article.
Now, new Vb.NET projects will have
Imports and Namespace in their code, which is similar to C#.