Visual Studio 2017でプロジェクトテンプレート作成

F#でWPFプログラミングをする際、プロジェクトテンプレートにコンソールアプリケーションしか存在しないため、毎回参照設定などを追加する必要があります。

今回はWPF用のプロジェクトテンプレートを作成してみたいと思います。

テンプレートの準備

まずは普通にコンソールアプリケーションプロジェクトを作成します。(名前は何でもいいです。)
f:id:any-programming:20170524182809p:plain

WPFに必要な参照を追加します。
f:id:any-programming:20170524183029p:plain

MainWindow.xamlファイルを追加(xmlファイルなどを追加して拡張子変更)し、ビルドアクションをResourceにします。
f:id:any-programming:20170524183500p:plain

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>

    </Grid>
</Window>


Program.fsを下記のように書き換えます。

open System
open System.Windows

[<STAThread>]
[<EntryPoint>]
let main argv = 
    let window = Application.LoadComponent(Uri("MainWindow.xaml", UriKind.Relative)) :?> Window

    Application().Run(window) |> ignore
    0


テンプレート作成

テンプレートが準備できましたら、「プロジェクト」→「テンプレートのエクスポート」を選択します。
f:id:any-programming:20170524183829p:plain

プロジェクトテンプレートを選択し、次へを押します。(プロジェクトが複数ある場合はドロップダウンで選択してください。)
f:id:any-programming:20170524183924p:plain

テンプレート名などを設定し、完了を押します。
f:id:any-programming:20170524184504p:plain

プロジェクト作成

プロジェクト作成ダイアログを開くと、作成したテンプレートが追加されていることが確認できます。
f:id:any-programming:20170524185905p:plain

テンプレートの削除

下記3か所のフォルダから削除すれば、ダイアログに出てこなくなります。(Visual Studio側から削除する方法があれば更新します。)

ユーザー/Documents/Visual Studio 2017/MyExported Templates
ユーザー/Documents/Visual Studio 2017/Templates/ProjectTemplates
ユーザー/AppData/Roaming/Microsoft/VisualStudio/バージョン/ProjectTemplatesCache