Last week I created a Visual Studio custom tool to encrypt configuration files(more information about the process here and here). To simplify the usage and improve the discoverability I also created a custom Item Template.
But how can I automatically set this custom tool when a new item is created?
- Open the .vstemplate-file.
- Add a WizardExtension-node to the XML file:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item"> | |
<TemplateData> | |
<DefaultName>Encrypted Config.encryptedconfig</DefaultName> | |
<Name>Encrypted Config</Name> | |
<Description>Encrypted Config</Description> | |
<ProjectType>CSharp</ProjectType> | |
<SortOrder>10</SortOrder> | |
<Icon>__TemplateIcon.ico</Icon> | |
</TemplateData> | |
<WizardExtension> | |
<Assembly>Microsoft.VSDesigner, Version=10.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly> | |
<FullClassName>Microsoft.VSDesigner.ProjectWizard.ItemPropertyWizard</FullClassName> | |
</WizardExtension> | |
<TemplateContent> | |
<References /> | |
<ProjectItem SubType="" TargetFileName="$fileinputname$.encryptedconfig" ReplaceParameters="false">test.encryptedconfig</ProjectItem> | |
<ProjectItem SubType="" TargetFileName="$fileinputname$.config" ReplaceParameters="true">test.config</ProjectItem> | |
</TemplateContent> | |
</VSTemplate> |
- Afterwars specify a CustomTool attribute on the ProjectItem:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item"> | |
<TemplateData> | |
<DefaultName>app.encryptedconfig</DefaultName> | |
<Name>Encrypted Config</Name> | |
<Description>Encrypted Config</Description> | |
<ProjectType>CSharp</ProjectType> | |
<SortOrder>10</SortOrder> | |
<Icon>__TemplateIcon.ico</Icon> | |
</TemplateData> | |
<WizardExtension> | |
<Assembly>Microsoft.VSDesigner, Version=10.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly> | |
<FullClassName>Microsoft.VSDesigner.ProjectWizard.ItemPropertyWizard</FullClassName> | |
</WizardExtension> | |
<TemplateContent> | |
<References /> | |
<ProjectItem SubType="" TargetFileName="$fileinputname$.encryptedconfig" ReplaceParameters="false" CustomTool="EncryptedConfigGenerator">app.encryptedconfig</ProjectItem> | |
</TemplateContent> | |
</VSTemplate> |