Deploying a Custom Directive Processor
This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
To use a custom directive processor in Visual Studio on any computer, you must register it by one of the methods described in this topic.
The alternative methods are:
Visual Studio Extension (VSIX). This provides a way to install and uninstall the directive processor both on your own computer and on other computers. Typically, you might package other features in the same VSIX.
VSPackage. If you are defining a VSPackage that contains other features in addition to the directive processor, there is a convenient method of registering the directive processor.
Set a registry key. In this method, you add a registry entry for the directive processor.
You need to use one of these methods only if you want to transform your text template in Visual Studio or MSBuild. If you use a custom host in your own application, your custom host is responsible for finding the directive processors for each directive.
Deploying a Directive Processor in a VSIX
You can add a custom directive processor to a Visual Studio Extension (VSIX).
You need to make sure that the following two items are contained in the .vsix file:
The assembly (.dll) that contains the custom directive processor class.
A .pkgdef file that registers the directive processor. The root name of the file must be the same as the assembly. For example, your files could be named CDP.dll and CDP.pkgdef.
To inspect or change the content of a .vsix file, change its file name extension to .zip and then open it. After editing the contents, change the filename back to .vsix.
There are several ways of creating a .vsix file. The following procedure describes one method.
To develop a custom directive processor in a VSIX project
Create a VSIX project in Visual Studio.
- In the New Project dialog box, expand Visual Basic or Visual C#, then expand Extensibility. Click VSIX Project.
In source.extension.vsixmanifest, set the content type and supported editions.
In the VSIX manifest editor, on the Assets tab, choose New and set the new item’s properties:
Content Type = VSPackage
Source Project = <the current project>
Click Selected Editions and check the types of installation on which you want the directive processor to be usable.
Add a .pkgdef file and set its properties to be included in the VSIX.
Create a text file and name it <assemblyName>.pkgdef.
<assemblyName> is usually the same as the name of the project.
Select it in Solution Explorer and set its properties as follows:
Build Action = Content
Copy to Output Directory = Copy Always
Include in VSIX = True
Set the name of the VSIX and make sure that the ID is unique.
Add the following text to the .pkgdef file.
[$RootKey$\TextTemplating] [$RootKey$\TextTemplating\DirectiveProcessors] [$RootKey$\TextTemplating\DirectiveProcessors\ CustomDirectiveProcessorName] @="Custom Directive Processor description" "Class"="NamespaceName.ClassName" "CodeBase"="$PackageFolder$\AssemblyName.dll"
Replace the following names with your own names:
Add the following references to the project:
Add your custom directive processor class to the project.
To install the Custom Directive Processor
In Windows Explorer (File Explorer in Windows 8), open the build directory (usually bin\Debug or bin\Release).
If you want to install the directive processor on another computer, copy the .vsix file to the other computer.
Double-click the .vsix file. The Visual Studio Extension Installer appears.
Restart Visual Studio. You will now be able to run text templates that contain directives that refer to the custom directive processor. Each directive is of this form:
<#@ CustomDirective Processor="CustomDirectiveProcessorName" parameter1="value1" … #>
To uninstall or temporarily disable the custom directive processor
In the Visual Studio Tools menu, click Extension Manager.
Select the VSIX that contains the directive processor, and then click Uninstall or Disable.
Troubleshooting a Directive Processor in a VSIX
If the directive processor does not work, the following suggestions might help:
The Processor name that you specify in the custom directive should match the
CustomDirectiveProcessorNamethat you specified in the .pkgdef file.
IsDirectiveSupportedmethod must return
truewhen it is passed the name of your
If you cannot see the extension in Extension Manager, but the system will not allow you to install it, delete the extension from %localappdata%\Microsoft\VisualStudio\*.0\Extensions\.
Open the .vsix file and inspect its contents. To open it, change the filename extension to .zip. Verify that it contains the .dll, .pkgdef, and extension.vsixmanifest files. The extension.vsixmanifest file should contain the appropriate list in the SupportedProducts node, and should also contain a VsPackage node under the Content node:
Deploying a Directive Processor in a VSPackage
If your directive processor is part of a VSPackage that will be installed in the GAC, you can have the system generate the .pkgdef file for you.
Place the following attribute on your package class:
[ProvideDirectiveProcessor(typeof(DirectiveProcessorClass), "DirectiveProcessorName", "Directive processor description.")]
This attribute is placed on the package class, not the directive processor class.
The .pkgdef file will be generated when you build the project. When you install the VSPackage, the .pkgdef file will register the directive processor.
Verify that the .pkgdef file appears in the build folder, which is usually bin\Debug or bin\Release. If it does not appear, open the .csproj file in a text editor, and remove the following node:
For more information, see VSPackages.
Setting a Registry Key
This method of installing a custom directive processor is the least preferred. It does not provide a convenient way enable and disable the directive processor, and does not provide a method of distributing the directive processor to other users.
Incorrectly editing the registry can severely damage your system. Before making changes to the registry, be sure to back up any valued data on the computer.
To register a directive processor by setting a registry key
In regedit, navigate to
If you want to install the directive processor in the experimental version of Visual Studio, insert "Exp" after "11.0".
Add a registry key that has the same name as the directive processor class.
- In the registry tree, right-click the DirectiveProcessors node, point to New, and then click Key.
In the new node, add string values for Class and CodeBase or Assembly, according to the following tables.
Right-click the node that you created, point to New, and then click String Value.
Edit the name of the value.
Double-click the name and edit the data.
If the custom directive processor is not in the GAC, the registry subkeys should look like the following table:
|(Default)||REG_SZ||(value not set)|
|Class||REG_SZ||<Namespace Name>.<Class Name>|
|CodeBase||REG_SZ||<Your Path>\<Your Assembly Name>|
If the assembly is in the GAC, the registry subkeys should look like the following table:
|(Default)||REG_SZ||(value not set)|
|Class||REG_SZ||<Your Fully Qualified Class Name>|
|Assembly||REG_SZ||<Your Assembly Name in the GAC>|