使用 DTE 将现有文件添加到 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 中时,该过程运行完成,但没有任何文件添加到项目中。我必须手动显示隐藏文件,然后将它们包含在项目中。
我如何添加文件才能使其工作?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@ritcoder - 当然:
我认为这个线程为您的问题提供了解决方案 - Visual Studio 宏:查找项目中未包含的文件?
@ritcoder - sure:
I think this thread provides the solution for your question - Visual Studio macro: Find files that aren't included in the project?