This sample demonstrates how to build a single file generator.


Quick Navigation

1 Requirements
2 Download and Install
3 Building and Running
4 Getting Started
4.1 Project Files
4.2 Unit Tests
4.3 Functional Tests
4.4 Status
4.5 History
4.6 Additional Resources


Visual Studio 2010 and Visual Studio 2010 SDK

Download and Install


Building and Running

To build and execute the sample, press F5 after the sample is loaded. This will launch the experimental hive which will demonstrate the sample's function.

Getting Started

The sample shows how to implement a single file generator. It demonstrates leveraging CodeDom to generate source code in Visual Basic, C#. It also demonstrates how to validate a XML document against a schema and communicate errors through the Error List.

Project Files


File Name Description
AssemblyInfo This file contains assembly custom attributes.
BaseCodeGenerator Abstract class that implements the IVsSingleFileGenerator interface.
BaseCodeGeneratorWithSite Abstract class that inherits from BaseCodeGenerator and implements the IObjectWithSite interface.
XmlClassGenerator The single file generator class.
SourceCodeGenerator Static class that contains the CodeDom code used to generate source code.
Support Static class containing support functions.
XmlClassGeneratorSchema.xsd Schema for XML documents that the generator knows how to convert into source code.
Strings.resx Resource strings (localizable). Class diagram for all types defined in this project.

Unit Tests


Create generator instance
Verify that QI for IVsSingleFileGenerator succeeds
Verify that a single file generator registration attribute is created
Verify that Register method gets appropiately invoked
Verify that Un-Register method gets appropiately invoked

Functional Tests


Load the sample
Verify the sample builds in Debug Configuration
Verify the sample builds in Release Configuration
Verify that the generator is properly registered when building
Verify that the generator works (C#).
Verify that the generator works (Visual Basic).
Verify that the generator works (J#).
Verify that the generator fails for bad XML (C#).
Verify that the generator fails for bad XML (Visual Basic).
Verify that the generator fails for bad XML (J#).



Function Status
Demonstrates Accessibility Yes
Includes Architecture Diagram Yes
Demonstrates Error Handling No
Follows SDK Coding Standards Yes
Demonstrates Localization Yes
Implements Functional Tests Yes
Sample supported by Microsoft Yes
Implements Unit Tests Yes



Date Activity
2005-10-04 Created this sample for the Visual Studio 2005 SDK
2010-03-05 Ported this sample to work in Visual Studio 2010

Additional Resources



Implementing and Registering Single File Generators