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;
}
}
}
如果我的項目名是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文件。但是當我使用這個模板創建一個項目時,我仍然將classname命名爲TestClassViewModel。
我在這裏做錯了什麼?
感謝,
RDV