We will place it in this variable so that our Interface methods (such as the IEnumerable interface) have access to it. This variable is populated from Visual Studio, it generally contains the actual string contents of the source file. Our class then declares a few private instance variables to provide as service fields to our concrete sub-class. The Visual Studio specific interfaces are IVsSingleFileGenerator, and IObjectWithSite, these interfaces supply Visual Studio with the hooks it needs to actually initialize and execute the Custom Tool. This type may be an, or some other type if you are performing some custom deserialization of the stream. The result of this is, our class will provide strongly typed enumeration facilities, to retrieve each element type from the underlying file.
This class also implements IEnumerable, which also receives the IterativeElementType type for its enumeration type. The class uses a generic type declaration, defining IterativeElementType as the type that will be passed to our generation methods. ServiceProvider = new ServiceProvider(oleServiceProvider) Private ServiceProvider SiteServiceProvider Private ServiceProvider serviceProvider = null
We define our class as abstract, so that we force the implementation to declare certain methods required for the iterative and generation process.Ĭopy Code public abstract class VsMultipleFileGenerator : You will need the following references added to your project to use the required classes and interfaces.
You can download this from the Microsoft Visual Studio Extensibility website. The attached project implements an abstract base class (an implementation of IVsSingleFileGenerator) which is easily subclassed to implement multiple file generation.įirstly, let's begin the class declaration: Required References and Prerequisitesīefore you begin, you will need to make sure that you have the Visual Studio SDK installed, to have access to the assemblies you will need. To begin, I will explain the inner workings of the base class. NET 2.0, and generics to make the implementation highly flexible, allowing you to simply override the base class, named ' VsMultipleFileGenerator', and implement 3 simple methods. Obviously, generating multiple files from a single source is going to have some inherent application specific dependencies.įor example, if your input file is HTML, and you are going to generate a child file for each occurrence of the tag in that HTML, you are going to need specific code to find each instance, and then iteratively perform the 'generation' routines.
An Extensible Approach to Multiple File Generation
This document explains how to create a reusable base class, which overcomes the 'Single File' limitation.įor information on creating Custom Tools, please read Jasmin Muharemovics article titled " VS.NET CodeDOM-Based Custom Tool for String Resource Management". This document does not explain the procedure for creating or deploying a Custom Tool, you are expected to already know this. This interface, .IVsSingleFileGenerator, unfortunately, only contains hooks for generating a single destination file from each source file. One pre-requisite of a Custom Tool is that it implements a specific Managed Interface, to allow Visual Studio to call the transformation, for a given file. This allows Visual Studio to instantiate the Custom Tool, and execute its interface methods to generate the required output. The name that is placed in the "Custom Tool" attribute, is simply referring to a node in the registry, which in turn, points to an Assembly and a Type in that Assembly (in the case of Custom Tools written in Managed Code). The complexities behind creating and deploying your own Custom Tools are surprisingly few. When this attribute is set correctly, it refers to an Assembly/Type that can generate a new file (whenever the source file is saved), based upon the source file as input, and store it as a child node of the source file, in the Solution Explorer.Įxamples of this are the MSDiscoGenerator, MSDataSetGenerator and ResXFileCodeGenerator. One of these is the "Custom Tool" attribute. When a file is selected in the Solution Explorer, the property grid displays several attributes, common across any file type. It also provides a rich extensibility API for customizing it for your specific needs.Ī good example of this is the highly utilized "Custom Tool" facility. Visual Studio is a great environment for Rapid Application Development.