2017-03-17 9 views
0

クラス名がユーザー提供のプロジェクト名と一致するようにプロジェクトテンプレートを作成したいとします。VSプロジェクトテンプレートのクラス名を変更する

私のクラスは(エクスポートProjectTemplate中)のように定義されます。

namespace $safeprojectname$.ViewModels 
{ 
    [Export("$safeprojectname$.ViewModels.TestClassViewModel ",typeof(ContentPaneViewModel))] 
    [PartCreationPolicy(CreationPolicy.NonShared)] 
    public class TestClassViewModel : ContentPaneViewModel 
    { 
     [ImportingConstructor] 
     public TestClassViewModel ([Import("$safeprojectname$.Views.TestClassView")]IView theView) 
     { 
      View = theView; 
      View.ViewModel = this; 
     } 
    } 
} 

私ProjectNameは、ABCProjであれば、私はTestClassViewModelがABCProjViewModelとして作成することにしたいです。これを達成するために、プロジェクトテンプレートのクラスファイルを次のように更新しました。

namespace $safeprojectname$.ViewModels 
{ 
    [Export("$safeprojectname$.ViewModels.$safeprojectname$",typeof(ContentPaneViewModel))] 
    [PartCreationPolicy(CreationPolicy.NonShared)] 
    public class $safeprojectname$: ContentPaneViewModel 
    { 
     [ImportingConstructor] 
     public $safeprojectname$([Import("$safeprojectname$.Views.TestClassView")]IView theView) 
     { 
      View = theView; 
      View.ViewModel = this; 
     } 
    } 
} 

変更を保存してプロジェクトテンプレートzipファイルを再作成しました。しかし、私はこのテンプレートを使用してプロジェクトを作成したとき、私はまだTestClassViewModelとしてclassnameを持っています。

私はここで間違っていますか?

おかげで、私はそれを行うためのより良い方法を考え出した

答えて

0

RDV:

1. Install visual studio extensibility tools for creating templates. 
2. Create Project & Item templates separately. 
3. In Project template just create folders, references, and resource dictionary, if any. 
4. Create class files in item template 
5. Make sure when putting a variable like $safeitemname$ or $projectname$, make sure .vstemplate & project.csproj has the same filename. 

おかげで、

RDV

関連する問題