[Visual Studio] 自訂 Item Template

為了方便自己以為建立coding standard, 制造一堆template 是其中一個方法. 有時候會copy and paste 一堆相類似的code再修改. 雖然能夠達到目的, 但費時失事. 所以Item Template 應運而生.

然而, 做了Item Template 後, 總會有若干修改以更貼合需求, 故記錄如下.

Item Template 預設會放於
%user_profile_path%\Documents\Visual Studio 2015\Templates\ItemTemplates\, 於VS內亦可以修改.

2016-09-08-10_09_56-pc0238v-vs2015-vmware-workstation

而Item Template 本身為一個zip file,透過VS 產生的話, 其內容如下:

2016-09-08-10_14_48-pc0238v-vs2015-vmware-workstation

內容

<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
  <!-- 設定 Item Template 內的Metadata. -->
  <TemplateData>
    <!-- 設定輸入的預設值. -->
    <DefaultName>ng-metadata component template.ts</DefaultName>
    <!-- 設定Item Template 的名字. -->
    <Name>ng-metadata component template</Name>
    <!-- 設定簡介. -->
    <Description>Webpack-enabled ng-metadata component template</Description>
    <!-- 設定語言. -->
    <ProjectType>CSharp</ProjectType>
    <!-- 設定於Item list 內的順序. -->
    <SortOrder>10</SortOrder>
    <!-- 設定圖示. -->
    <Icon>__TemplateIcon.ico</Icon>
  </TemplateData>
  <!-- Item template 內檔案. 可以基於輸入的file name 再rename. -->
  <TemplateContent>
    <References />
    <ProjectItem SubType="Code" TargetFileName="$fileinputname$.component.ts" ReplaceParameters="true">sample.component.ts</ProjectItem>
    <ProjectItem SubType="Code" TargetFileName="$fileinputname$.component.html" ReplaceParameters="true">sample.component.html</ProjectItem>
  </TemplateContent>
</VSTemplate>

Reference:

About C.H. Ling 260 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.