2013-08-02 70 views
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

+0

你有什么问题f或者当您运行已发布的代码时的示例 – MethodMan

+0

我创建了项目类。我不确定我应该使用什么课程。 –

+0

可能的重复[如何将现有表单添加到新项目?](http://stackoverflow.com/questions/10316650/how-do-you-add-an-existing-form-to-a-new -project) – MethodMan

回答

3

VisualStudio的项目仅仅是一个XML文件,这样就可以使用的XDocument或XmlDocument的和编辑打开它。

+1

源代码管理将不知道您添加了新文件。 –

+0

@IsaacKleinman不知道我明白为什么它不知道?它将是源代码管理将识别的xml文件的更新。 –

+1

scc会看到'csproj'已经改变,但不会检测到添加的文件。显然,该功能由“添加新/现有项目”功能处理。 –

1

尝试这样:

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

相关问题