0

I want to create a project template such that class name matches user provided project name.

My class is defined as (in exported 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;
        }
    }
}

If my ProjectName is ABCProj, then I want TestClassViewModel to be created as ABCProjViewModel. TO achieve that I updated the class file in Project template as:

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;
        }
    }
}

Saved the changes and recreated the Project Template zip file. But when i created a project using this template, I still got classname as TestClassViewModel.

What is that I am doing wrong here?

Thanks,

RDV

RDV
  • 957
  • 13
  • 28

1 Answers1

0

I have figured out a better way of doing it:

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.

Thanks,

RDV

RDV
  • 957
  • 13
  • 28