VSIX Tutorial-Adding a wizard on template

Add supporting classes and files

The new Lib project

Modifying the main project

<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

<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>
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.

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;
}
[IniSetup]
Locale=$iniSelectedCulture$
    <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 :)

Screenshot

You can download the code


Last modified on: December 03, 2013