2

如何以编程方式将项目添加到项目中?

类似的东西

public void AddExistingItem(string projectPath, string existingItemPath)
{
    //I'm making up the Project class here as an example
    Project p = new Project(projectPath);
    p.AddExistingItem(existingItemPath);
}

我想模仿 Visual Studio 的 Add Existing Item 功能。

添加现有项目

4

3 回答 3

3

VisualStudio 项目只是一个 XML 文件,因此您可以使用 XDocument 或 XmlDocument 打开它并进行编辑。

于 2013-08-02T15:01:56.237 回答
2

添加对 EnvDTE.dll 的引用,然后使用ProjectItems.AddFromFile方法
如您在此页面上阅读的那样,如果添加对 EnvDTE.dll 的引用,则必须将程序集的Embed Interop Types属性设置为false

于 2013-08-02T15:03:52.563 回答
0

尝试这样的事情:

public void createProjectItem(DTE2 dte)
{
    //Adds a new Class to an existing Visual Basic project.
    Solution2 soln;
    Project prj;
    soln = (Solution2)_applicationObject.Solution;
    ProjectItem prjItem;
    String itemPath;
    // Point to the first project (the Visual Basic project).
    prj = soln.Projects.Item(1);
    // Retrieve the path to the class template.
    itemPath = soln.GetProjectItemTemplate("Class.zip", "vbproj");
    //Create a new project item based on the template, in this
    // case, a Class.
    prjItem = prj.ProjectItems.AddFromTemplate(itemPath, "MyNewClass");
}

来自:http: //msdn.microsoft.com/en-us/library/vstudio/ms228774.aspx

于 2013-08-02T15:02:06.383 回答