VSIX Tutorial-Adding a wizard on template
Add supporting classes and files
The new Lib project
- Create a new Class Library project MyExtension.Lib and remove the auto generated class
- Add a new existing item, selecting as action, instead of Add, the choice "Add as Link" the Key.snk inside the MyExtension project
- On the MyExtension.Lib project properties sign the assembly with the .snk just added
Modifying the main project
- Add a reference to the System Assembly "Microsoft.VisualStudio.TemplateWizardInterface"
- Add the reference on MyExtension
- Compile everything
- Open the Visual Studio Command Prompt. We will get the PublicKeyToken
- Set the path to the Output Directory of the main project (e.g. "CD C:\Solutions\MyExtension\MyExtension\bin\Debug")
- Run "sn -T MyExtension.Lib.dll"
- Save the Public key token for later (for me it's 512d566d7de30037)
- Add the new assembly to the Assets inside the vsixmanifest. The AssemblyName is the Full qualified name of the assembly.
<Asset Type="Microsoft.VisualStudio.Assembly" Path="MyExtension.Lib.dll" AssemblyName="MyExtension.Lib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=512d566d7de30037" />
Creating the wizard dialog and Wizard
This dialog will let us choose the locale that will be used inside the ini file
- Create a new WPF Windos "Wizards\IniWizardDialog.xaml
<Window x:Class="MyExtension.Lib.Wizards.IniWizardDialog" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" ResizeMode="NoResize" Title="Ini Generation Wizard" ShowInTaskbar="False" WindowStartupLocation="CenterOwner" Height="128" Width="300" HorizontalAlignment="Center"> <Grid> <Label Content="Culture" HorizontalAlignment="Left" Margin="10,20,0,0" VerticalAlignment="Top" Width="70"/> <ComboBox x:Name="ComboBoxCulture" HorizontalAlignment="Left" Margin="100,20,0,0" VerticalAlignment="Top" Width="180"/> <Button x:Name="ButtonOk" Content="OK" HorizontalAlignment="Left" Margin="100,60,0,0" VerticalAlignment="Top" Width="80" RenderTransformOrigin="0.458,-0.85" Click="ButtonOkClick"/> <Button x:Name="ButtonCancel" Content="Cancel" HorizontalAlignment="Left" Margin="200,60,0,0" VerticalAlignment="Top" Width="80" RenderTransformOrigin="0.458,-0.85" Click="ButtonCancelClick"/> </Grid> </Window>
- Setup the various handlers and variables inside the Code Behind
public partial class IniWizardDialog
{
public string SelectedCulture { get; private set; }
public IniWizardDialog()
{
InitializeComponent();
InitializeCultures();
}
private void InitializeCultures()
{
var cbp = new List<ComboBoxPair>
{
new ComboBoxPair("en-US", "English US"),
new ComboBoxPair("en-UK", "English UK"),
new ComboBoxPair("it-IT", "Italian"),
new ComboBoxPair("fr-FR", "French")
};
ComboBoxCulture.DisplayMemberPath = "Description";
ComboBoxCulture.SelectedValuePath = "Key";
ComboBoxCulture.ItemsSource = cbp;
ComboBoxCulture.SelectedIndex = 0;
}
private void ButtonOkClick(object sender, RoutedEventArgs e)
{
SelectedCulture = ComboBoxCulture.SelectedValue.ToString();
Close();
}
private void ButtonCancelClick(object sender, RoutedEventArgs e)
{
SelectedCulture = null;
Close();
}
}
Now the real wizard should be created.
- Add a reference to the System Assembly "Microsoft.VisualStudio.TemplateWizardInterface"
- Add a reference to the System Assembly "EnvDTE"
- Add the new Class Wizards\IniWizard.cs implementing IWizard. All methods must be empty but the following:
private bool _shouldAddProjectItem;
public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary,
WizardRunKind runKind, object[] customParams)
{
_shouldAddProjectItem = false;
var inputForm = new IniWizardDialog();
inputForm.ShowDialog();
if (inputForm.SelectedCulture == null) return;
_shouldAddProjectItem = true;
replacementsDictionary.Add("$iniSelectedCulture$", inputForm.SelectedCulture);
}
public bool ShouldAddProjectItem(string filePath)
{
return _shouldAddProjectItem;
}
- The replacementsDictionary is the dictionary that will be applied to the template when the "ReplaceParameters" is set to true inside the .vstemplate file
- We add the $iniSelectedCulture$ parameter!
- Opening the tiniTemplate.tini we will replace the Locale=en-US with the new replacement parameter $iniSelectedCulture$
[IniSetup] Locale=$iniSelectedCulture$
- As the last step we add to the template the wizard, inside the .vstemplate file
<WizardExtension> <Assembly>MyExtension.Lib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=512d566d7de30037</Assembly> <FullClassName>MyExtension.Lib.Wizards.IniWizard</FullClassName> </WizardExtension>
Conclusion
Now everything is in place! And creating a new project item will set the culture :)

You can download the code