2013-08-02 114 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

相關問題