我在visual studio 2012上使用c#编写了一个Visual Studio向导模板。
我遵循MSDN步骤:我创建了一个VS模板,然后创建了一个类库项目,其中包含一个实现IWizard接口的类,我配置了.vstemplate文件等...
在我的类库项目中,我从计算机的某个目录中复制现有的解决方案,我将新生成的项目添加到该解决方案,然后运行它。
我这样做:
public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
{
solutionDir = replacementsDictionary["$solutiondirectory$"];
destProjectDir = replacementsDictionary["$destinationdirectory$"];
projName = replacementsDictionary["$specifiedsolutionname$"];
EmulationDir = @"MY_PATH\TestSln";
DirectoryCopy(EmulationDir, solutionDir);
dte = (DTE2)automationObject;
}
public void RunFinished()
{
Solution2 solution;
Project p;
solution = (Solution2)dte.Solution;
solution.Open(solutionDir + "\\TestSln.sln");
p = solution.AddFromFile(destProjectDir + "\\" + projName + ".vcxproj");
}
但是我必须将新项目添加到解决方案的特定子文件夹中:上面的代码直接将新项目添加到解决方案中,我想将它添加到solutionDir \ apps。
你知道怎么办吗? 谢谢!
答案 0 :(得分:6)
您可以使用SolutionFolder
界面完成此操作:
Project project = getSolutionSubFolder(solution, "SubFolderName");
if (project != null)
{
SolutionFolder folder = (SolutionFolder)project.Object;
folder.AddFromFile("yourProjectFilePath");
}
getSolutionSubFolder
方法如下所示:
private static Project getSolutionSubFolder(Solution2 solution, string subfolder)
{
return
solution
.Projects
.Cast<Project>()
.FirstOrDefault(
p => string.Equals(p.Name, subfolder, StringComparison.Ordinal));
}