Microsoft KB Archive/870715

= How to create a custom code template in Visual Studio 2005 or in Visual Studio .NET =

Article ID: 870715

Article Last Modified on 11/14/2007

-

APPLIES TO


 * Microsoft Visual Studio 2005 Standard Edition
 * Microsoft Visual Studio 2005 Professional Edition
 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Academic Edition
 * Microsoft Visual C# 2005 Express Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition

-





IN THIS TASK

 * INTRODUCTION
 * Change the LocalProjectItems.vsdir file
 * Create a custom Windows form wizard
 * Create a custom Windows form template
 * Open the template in Visual Studio .NET
 * REFERENCES



INTRODUCTION
This step-by-step article describes how to create a custom code template in a Microsoft Visual C# 2005 or Microsoft Visual C# .NET Windows application project and then add it to the Visual Studio 2005 or Visual Studio .NET IDE.

back to the top 

MORE INFORMATION
To create a custom code template in a Microsoft Visual C# 2005 or Microsoft Visual C# .NET Windows application project and then add it to the Visual Studio 2005 or Visual Studio .NET IDE, follow these steps.

Change the LocalProjectItems.vsdir file
 Right-click My Computer, and then click Explore. Locate the LocalProjectItems folder.

In Microsoft Visual Studio .NET 2003, the folder is located in the following path:



In Microsoft Visual Studio .NET 2002, the folder is located in the following path:



Note  represents the hard disk drive where you installed Visual Studio .NET. Create a new MyCustomTemplates folder in the LocalProjectItems folder. Copy the LocalProjectItems.vsdir file to the MyCustomTemplates folder.

In Microsoft Visual Studio .NET 2003, the LocalProjectItems.vsdir file is located in the following path:



In Microsoft Visual Studio .NET 2002, the LocalProjectItems.vsdir file is located in the following path:



 In the MyCustomTemplates folder, open the LocalProjectItem.vsdir file by using Notepad, and then replace the existing text with the following text:

..\..\MyCustomTemplatesWinFormWiz.vsz|{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}|#2237|10|#2264|{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}|4535|0|Form.cs

 Save the file, and then quit Notepad.</li></ol>

back to the top

Create a custom Windows form wizard
<ol> Open the CSharpProjectItems folder.

In Visual Studio .NET 2003, the folder is located in the following path:



In Visual Studio .NET 2002, the folder is located in the following path:



</li> Copy the CSharpAddWinFormWiz.vsz file to the CSharpProjectItems folder, and then rename the file to MyCustomTemplatesWinFormWiz.vsz.</li> Open the MyCustomTemplatesWinFormWiz.vsz file by using Notepad, and then change the wizard name parameter value to the following:

<pre class="fixed_text">Param=&quot;WIZARD_NAME = MyCustomTemplatesWinFormWiz&quot;

</li> Save the file, and then quit Notepad.</li></ol>

back to the top

Create a custom Windows form template
<ol> Open the VC#Wizards folder.

In Visual Studio .NET 2003, the folder is located in the following path:



In Visual Studio .NET 2002, the folder is located in the following path:



</li> Copy the CSharpAddWinFormWiz folder to the VC#Wizards folder, and then change the name of the the CSharpAddWinFormWiz folder to MyCustomTemplatesWinFormWiz.</li> Double-click the MyCustomTemplatesWinFormWiz folder, open the Templates folder, and then double-click the 1033 folder.</li> Open the NewWinForm.cs file by using Notepad.</li> Add the lines of code that you use frequently to the top of the NewWinForm.cs file.</li> Save the file, and then quit Notepad.</li></ol>

back to the top

Open the template in Visual Studio .NET

 * 1) Start Visual Studio .NET.
 * 2) On the File menu, point to New, and then click Project.
 * 3) Under Project Types, click Visual C# Projects.
 * 4) Under Templates, click WindowsApplication.
 * 5) Click OK. By default, the Form1 form appears.
 * 6) On the Project menu, click Add New Item. The Add New Item -   dialog box appears.

Note  is a placeholder for the name of the Windows application that you created.
 * 1) Under Categories, expand Local Project Items, click MyCustomTemplates, and then click Open. By default, the Form2.cs file is created.
 * 2) Right-click the Form2 form, and then click View Code.
 * 3) The code that you see is the code that you added in step 5 of the &quot;Create a custom Windows form template&quot; section.

back to the top

<div class="references_section">