如何以编程方式将文件添加到解决方案? [英] How do I programmatically add a file to a Solution?

查看:85
本文介绍了如何以编程方式将文件添加到解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发VS软件包,我需要实现的功能的一部分是向当前打开的解决方案的解决方案项中添加文件.

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.

我已经很好地了解了DTE和DTE2接口,可以看到添加和操作项目的操作,但是似乎没有用于添加单个文件的任何操作.

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.

谢谢.

推荐答案

好吧,我意识到我可以只记录一个Macro来捕获操作,然后在VS Macro IDE中检查代码.

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);

这篇关于如何以编程方式将文件添加到解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆