Reputation: 2703
I want to create a template for example (Create a folder in the folder create 1 class and 1 interface with the names of the folder) and it will be created by right click on the project and in the menu, it will appear CreateTamplateClass
Can I do it using c# WinForms / Console Application and more .. ?
TNX
Upvotes: 2
Views: 561
Reputation: 125217
You can create a C# Item Template project or manually create the item template zip file yourself.
The item template zip file should contain the following files:
Class.cs
Interface.cs
MyItemTemplate.vstemplate
Then you need to copy the zip file to following folder:
%USERPROFILE%\Documents\Visual Studio 2017\Templates\ItemTemplates\Visual C#
Then open a new instance of Visual Studio and create/open a C# project, then open Add New Item window and choose MyItemTemplate from Visual C# Items and assing a name like MyItem1, then the following structure will be created:
Here is the content for template files in the zip file:
Class.cs
using System;
using System.Collections.Generic;
namespace $rootnamespace$.$basename$
{
class $safeitemrootname$: I$safeitemrootname$
{
}
}
Interface.cs
using System;
using System.Collections.Generic;
namespace $rootnamespace$.$basename$
{
interface $safeitemrootname$
{
}
}
MyItemTemplate.vstemplate
<?xml version="1.0" encoding="utf-8"?>
<VSTemplate Version="3.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" xmlns:sdk="http://schemas.microsoft.com/developer/vstemplate-sdkextension/2010">
<TemplateData>
<Name>MyItemTemplate</Name>
<Description>My multi-file item template</Description>
<Icon>MyItemTemplate.ico</Icon>
<TemplateID>52ae3bdb-7fde-4d47-8a4b-d17d0c9269f7</TemplateID>
<ProjectType>CSharp</ProjectType>
<DefaultName>MyItem.cs</DefaultName>
</TemplateData>
<TemplateContent>
<References>
<Reference>
<Assembly>System</Assembly>
</Reference>
</References>
<ProjectItem TargetFileName="$fileinputname$\I$fileinputname$.cs" ReplaceParameters="true">Interface.cs</ProjectItem>
<ProjectItem TargetFileName="$fileinputname$\$fileinputname$.cs" ReplaceParameters="true">Class.cs</ProjectItem>
<CustomParameters>
<CustomParameter Name="$basename$" Value="$fileinputname$"/>
</CustomParameters>
</TemplateContent>
</VSTemplate>
Upvotes: 2