Introduction
Modified templates and JavaScript files will change the coding environment, such that it will make the VB.NET environment look like C# one. I hope, it will make C# people to work in VB.NET easily.
Adding Imports
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:
Imports System
on top of the template file and get this in your project.
Adding Namespace
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.
First, we must change both Form.vb files. The modified files are given below. We must add a variable in the template files and define those in the JavaScript files so that they will be changed according to the name of the project/output name.
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.
Check function 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.
Sample
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#.