我有一个项目模板,每当我尝试添加项目模板时,它都会在正确的位置(文件夹)中创建,但也会在添加到项目的第一个文件夹中添加该项目。我该如何解决?
代码:
if (project.Kind == PrjKind.prjKindCSharpProject) {
itemPath = solution.GetProjectItemTemplate("PriClass.zip", "CSharp");
fileExtension = ".cs";
} else {
itemPath = solution.GetProjectItemTemplate("PriClass.zip", "VisualBasic");
fileExtension = ".vb";
}
if (!String.IsNullOrEmpty(itemPath)) {
foreach(MyTreeNode type in selectedTypes) {
string[] namespaceParts = type.Namespace.Split('.');
if (namespaceParts.Length == 4) {
this.Module = namespaceParts[2];
this.ModuleType = namespaceParts[3];
this.ClassName = type.NodeName;
ProjectItem rootFolder = project.ProjectItems.Cast < ProjectItem > ()
.FirstOrDefault(i => i.Name == this.Module) ? ? project.ProjectItems.AddFolder(this.Module);
switch (this.ModuleType) {
case "Editors":
rootFolder.ProjectItems.AddFromTemplate(itemPath, "Ui" + this.ClassName + fileExtension);
break;
case "Services":
rootFolder.ProjectItems.AddFromTemplate(itemPath, "Api" + this.ClassName + fileExtension);
break;
}
}
}
创建后的项目: