How can I programmatically add an item to a project?
Something similar to
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);
}
I want to mimic Visual Studio's Add Existing Item functionality.
VisualStudio project is just a XML file so you can open it using XDocument or XmlDocument and edit.
Add a reference to EnvDTE.dll, and then use
ProjectItems.AddFromFile
methodAs you can read on this page, you must set the Embed Interop Types property of the assembly to
false
if you add a reference to EnvDTE.dllTry something like this:
from: http://msdn.microsoft.com/en-us/library/vstudio/ms228774.aspx