Search code examples
.netvisual-studio-2010vsxvspackage

How do I programmatically add a file to a Solution?


I am developing a VS Package and part of the functionality that I need to implement is to add a file to the Solution Items of the currently open Solution.

This is exactly the same action that would be performed manually if you right-click on a Solution and choose Add > Existing Item. Then selected a file on disk.

I have taken a good look at the DTE and DTE2 interfaces and can see the operations to add and manipulate projects but there doesn't appear to be any operations for adding individual files.

Thanks.


Solution

  • Ok, I realised I could just record a Macro to capture the operation then examine the code in the VS Macro IDE.

    The code required to do this is.

    DTE.ItemOperations.AddExistingItem(filePath);