How to programmatically add a file to a solution?

I am developing a VS package and part of the functions that I need to implement is to add a file to the solution elements of the currently open solution.

This is the same action that will be performed manually if you right-click on the solution and choose Add> Existing Element. Then select the file on disk.

I have become familiar with the DTE and DTE2 interfaces and see operations for adding and managing projects, but there are no operations for adding individual files.

Thank.

+5
source share
3 answers

Ok, I realized that I can just record a macro to capture the operation and then test the code in the VS Macro environment.

, , .

DTE.ItemOperations.AddExistingItem(filePath);
+9

ProjectItems AddFromFile()

ProjectItem pi = project.ProjectItems.AddFromFile(filePath);
+2

You need AddFromFileto collectionProjectItems Project

http://msdn.microsoft.com/en-us/library/envdte.projectitems.addfromfile(v=vs.100).aspx

edit:

To add to the solution, AddFromFileagainstSolution

-1
source

All Articles