ENVDTE - 将新项目添加到现有解决方案并将其定位在特定文件夹中 [英] ENVDTE - Add new project to existing solution and locate it in a specific folder

查看:31
本文介绍了ENVDTE - 将新项目添加到现有解决方案并将其定位在特定文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio 2012 上使用 c# 编写了一个 Visual Studio 向导模板.

I wrote a Visual Studio Wizard Template using c# on visual studio 2012.

我遵循了 MSDN 步骤:我创建了一个 VS 模板,然后我创建了一个类库项目,其中包含一个实现 IWizard 接口的类,我配置了 .vstemplate 文件等等...

I followed the MSDN steps: I created a VS template, then I created a Class Library project with a class which implements the IWizard interface, I configured the .vstemplate file and etc...

在我的类库项目中,我从计算机的某个目录复制现有解决方案,将新生成的项目添加到该解决方案中,然后运行它.

In my Class Library project I copy an existing solution from some directory in my computer, I add the new generated project to that solution, and run it.

我这样做:

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中.

but I have to add the new project to a specific sub-folder of the solution: the above code adds the new project to the solution straightly, and I'ld like to add it to the solutionDir\apps.

你知道这样做的方法吗?谢谢!!

Do you know about any way to do thus? thanks!!

推荐答案

您可以使用 SolutionFolder 界面:

You can accomplish this using SolutionFolder interface:

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

这篇关于ENVDTE - 将新项目添加到现有解决方案并将其定位在特定文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆