VC++ project “Include in project” programmatically

2019-08-21 12:10发布

Is there a way to include folder into VC++ project programmatically via VCProject or EnvDTE interface?

2条回答
Explosion°爆炸
2楼-- · 2019-08-21 12:44

I have done this only for C# and VB.NET projects, but it should be the same:

var pr = new Microsoft.Build.Evaluation.Project();  
//Initialize (load from file or whatever)    
pr.AddItem("Folder", YourFoldersPath + @"\");  
pr.Save()
查看更多
劳资没心,怎么记你
3楼-- · 2019-08-21 12:57

Take a look at the sample macros - View -> Other Windows -> Macro Explorer. There's one in Samples/AddDirAsSlnFolder which shows you how to create nodes in a project and add files. It's in VisualBasic, but it's pretty easy to translate into C# once you see which methods in EnvDTE are used, eg

projItem = currentSlnFolder.Parent.ProjectItems.AddFromFile(file)

using EnvDTE.ProjectItems

查看更多
登录 后发表回答