Add Existing File To Visual Studio Project using DTE

4.5k Views Asked by At

I've programatically created a number of files. I want to add them to the visual studio project. I have a reference to the project (DTE.Project). When I execute the code below, I get an error message.

project.ProjectItems.AddFromFile(filename);

The error is

Exception at 'Expand' - 'Unable to add 'manage.txt'. A file with that name already exists.'
System.Runtime.InteropServices.COMException (0x80040400): Unable to add 'manage.txt'. A file with that name already exists.
at EnvDTE.ProjectItems.AddFromFile(String FileName)

When I wrap the call in a try-catch, the process runs to completion but non of the files are added to the project. I have to manually show hidden files and then include them in the project.

How do I add the file for this to work?

1

There are 1 best solutions below

0
On BEST ANSWER

@ritcoder - sure:

I think this thread provides the solution for your question - Visual Studio macro: Find files that aren't included in the project?