使用DTE将现有文件添加到Visual Studio项目中



我已经用程序创建了许多文件。我想把它们添加到visual studio项目中。我有一个对项目(DTE.project)的引用。当我执行下面的代码时,我会收到一条错误消息。

project.ProjectItems.AddFromFile(filename);

错误为

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)

当我将调用封装在try-catch中时,进程运行到完成,但没有任何文件添加到项目中。我必须手动显示隐藏的文件,然后将它们包含在项目中。

我如何添加文件以使其工作?

@ritcoder-确定:

我认为这个线程为您的问题提供了解决方案-Visual Studio宏:查找项目中不包含的文件?

最新更新