ソリューションのテンプレートにTagを付ける

もくじ
https://tera1707.com/entry/2022/02/06/144447

テンプレート関連記事

やりたいこと

前回、ソリューションのテンプレートを作って、新規slnを作ってのWinUI3の実験をやりやすくした。

ただ、テンプレートに「タグ」を付けてないので、テンプレートを使うときに、なんの括りにも属さないので探しにくい。

タグをつけて探しやすくする。

やり方

いじる.vstemplateはどれか?

一番親の.vstemplateに、タグをつけてやる。

│  WinUI3Template.vstemplate    ★ ★コレ! ★ ★
│  
├─WinUI3Template
│  │  app.manifest
│  │  App.xaml
│  │  App.xaml.cs
│  │  MainWindow.xaml
│  │  MainWindow.xaml.cs
│  │  MyTemplate.vstemplate    ★これではない
│  │  vstg0005.xaml
│  │  vstg0006.xaml
│  │  vstg0007.xaml
│  │  vstg0008.xaml
│  │  vstg0009.xaml
│  │  WinUI3Template.csproj
│  │  __TemplateIcon.ico
│  │  
│  ├─PROPERTIES
│  │  └─PUBLISHPROFILES
│  │          win10-x64.pubxml
│  │          
│  └─VIEW
│          MainPage.xaml
│          MainPage.xaml.cs
│          SubPage.xaml
│          SubPage.xaml.cs
│          vstg0001.xaml
│          vstg0002.xaml
│          vstg0003.xaml
│          vstg0004.xaml
│          
└─WinUI3TemplatePackage
    │  MyTemplate.vstemplate  ★これではない
    │  Package.appxmanifest
    │  WinUI3TemplatePackage.wapproj
    │  __TemplateIcon.ico
    │  
    └─IMAGES
            LockScreenLogo.scale-200.png
            SplashScreen.scale-200.png
            Square150x150Logo.scale-200.png
            Square44x44Logo.scale-200.png
            Square44x44Logo.targetsize-24_altform-unplated.png
            StoreLogo.png
            Wide310x150Logo.scale-200.png

いじりかた

下記のmsdocsに書いてある通りにする。

https://learn.microsoft.com/ja-jp/visualstudio/ide/template-tags?view=vs-2022

今回はこうした。

<VSTemplate Version="2.0.0" Type="ProjectGroup"
    xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
    <TemplateData>
        <Name>MyWinUI3PackageProjectTemplate</Name>
        <Description>WinUI3パッケージソリューションの自作テンプレート</Description>
        <Icon>Icon.ico</Icon>
        <ProjectType>csharp</ProjectType>
        <LanguageTag>csharp</LanguageTag>  ★コレ!
        <PlatformTag>windows</PlatformTag>  ★コレ!
        <ProjectTypeTag>winui</ProjectTypeTag>  ★コレ!
    </TemplateData>
    <TemplateContent>
        <ProjectCollection>
            <SolutionFolder Name="$projectname$">
                <ProjectTemplateLink ProjectName="$projectname$">
                    WinUI3Template\MyTemplate.vstemplate
                </ProjectTemplateLink>
                <ProjectTemplateLink ProjectName="$projectname$Package" CopyParameters="true">
                    WinUI3TemplatePackage\MyTemplate.vstemplate
                </ProjectTemplateLink>
            </SolutionFolder>
        </ProjectCollection>
    </TemplateContent>
</VSTemplate>

結果

上のタグをつけてzipに固めて、VSで新規プロジェクト作成をすると、下記のように分類されてくれる。