This repository contains an extensive Visual Studio project template and an item template creation example.
- How to create VSIX project?
- How to create an item template project?
- How to create a project template project?
- How to use Custom parameters in an item template or project template?
- How to implementation IWizard interface?
- How to create a form and how to shown this form when create an item?
- How to debug VSIX project?
Project Name | Project Type | |
---|---|---|
QuarantineTemplate.sln | Blank Solution | |
QuarantineTemplate | VSIX Project | Startup Project |
QuarantineEntityTemplate | C# Item Template Project | |
QuarantineRepositoryTemplate | C# Item Template Project | |
QuarantineWizard | Class Library (.NET Framework 4.8) |
├── QuarantineTemplate
│ ├── src
│ │ ├── QuarantineTemplate
│ │ │ └── QuarantineTemplatePackage.cs
│ │ │ └── source.extension.vsixmanifest
│ │ ├── QuarantineEntityTemplate
│ │ │ └── Entity.cs
│ │ │ └── EntityTemplate.ico
│ │ │ └── EntityTemplate.vstemplate
│ │ ├── QuarantineRepositoryTemplate
│ │ │ └── ...
│ │ ├── QuarantineWizard
│ │ │ ├── ItemComponents
│ │ │ │ ├── EntityClassComponent
│ │ │ │ │ └── FormEntityClassComponet.cs
│ │ │ ├── Wizards
│ │ │ │ └── WizardEntityClass.cs
│ ├── files
│ └── QuarantineTemplate.sln
│ └── README.md
│ └── LICENSE
│ └── .gitignore
- Create a new VSIX project within Visual Studio (New Project / Visual C# / Extensions) (VS2019)
- Select VSIX Project.
- QuarantineTemplate is a VSIX Project.
- Create a new C# Item Template Project within Visual Studio (New Project / Visual C# / Extensions) (VS2019)
- Select C# Item Template.
- QuarantineEntityTemplate and QuarantineRepositoryTemplate are C# Item Template projects.
Create an Class Library and install VSSDK.TemplateWizardInterface from nuget. Add a class and this class is inherit from the IWizard interface.
using EnvDTE;
using Microsoft.VisualStudio.TemplateWizard;
using QuarantineWizard.ItemComponents.EntityClassComponent;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
namespace QuarantineWizard.Wizards
{
public class WizardEntityClass : IWizard
{
private readonly FormEntityClassComponet _form = new FormEntityClassComponet();
private bool _userCancelled;
private DTE _currnetDte;
private static string _currentSolutionPath;
public void BeforeOpeningFile(ProjectItem projectItem)
{
}
public void ProjectFinishedGenerating(Project project)
{
}
public void ProjectItemFinishedGenerating(ProjectItem projectItem)
{
}
public bool ShouldAddProjectItem(string filePath)
{
return !_userCancelled;
}
public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
{
_currnetDte = (DTE)automationObject;
_currentSolutionPath = replacementsDictionary["$solutiondirectory$"];
using (_form)
{
_form.StrFormTitle = Path.GetFileName(replacementsDictionary["$title$"]);
_form.StrEntityClassName = Path.GetFileName(replacementsDictionary["$safeitemrootname$"]);
_form.StrEntitySchemaName = Path.GetFileName(replacementsDictionary["$schemaname$"]);
_form.StrEntityIdTypeName = Path.GetFileName(replacementsDictionary["$idtype$"]);
if (_form.ShowDialog() != DialogResult.OK)
{
_userCancelled = true;
return;
}
replacementsDictionary["$schemaname$"] = _form.StrEntitySchemaName;
replacementsDictionary["$idtype$"] = _form.StrEntityIdTypeName;
}
}
public void RunFinished()
{
}
}
}
To use this project in the item template or the project template, the key.snk file must be created.
How read your key.snk public token. It's easy with Visual Studio. Add new an external tool. Visual Studi -> Tools -> External Tools and open external tools window.
Now run added external tool and get token.
The token will use on project template or item template .vstemplate files.
- Create a new console application in a directory close to your project.
├── Projects
│ ├── QuarantineTemplate
│ ├── QuarantineTemplateDebugger
│ │ └── QuarantineTemplateDebugger.sln
- Open QuarantineTemplate properties debug tab and configure like this.