Description
This is the deep dive documentation for the Single File Generator sample inside the Visual Studio SDK. If you do not already have the Visual Studio SDK installed, you can download it from
http://msdn.com/vsx/.
Please click on the "Downloads" tab to download the deep dive documentation.
Introduction
Single file generators are a useful mechanism to support the development process by code generation. You can attach a single file generator to a source file through the files “Custom Tool” property. When you save the file the single file generator runs and creates source code by parsing the parent source file.
The most common reason of using single file generators is to help in repeatable and mechanical tasks, for example in using the same (and sometimes complex) code generation pattern for a (large) number of files. Let’s assume your source files can be XML structures each describing a business entity. You can use a single file generator to create the C# classes representing these entities.
One node in your XML structure can be represented with many code lines. By simply changing the information in the XML source files saves you a lot of work. You can even update the single file generator when your generation pattern changes.
This VS SDK sample demonstrates how to create a single file generator that parses an XML file and turns it into a C#, VB or J# source code file depending on the current project context.
By going through this deep dive you will get familiar with the following concepts:
What is a single file generator and when should you use one?
- How to register a single file generator with Visual Studio?
- What is the pattern used in this example to build the single file generator?
- How to access VS context information in single file generators?
- What are the roles of CodeDom and CodeDomProvider in code generation?
To understand concepts treated here it is assumed that you are familiar with the build process of VSPackages.