Вопрос

I'm developing VS extension which must reconstruct specified directory's tree structure via Filters and add existing files from that directory to appropriate filters.

How can I add Filters and existing files to project via code?

Это было полезно?

Решение 2

I found the following solution:

using Microsoft.VisualStudio.VCProjectEngine;
using Microsoft.VisualStudio.Shell.Interop;
//...
EnvDTE.DTE dte = (EnvDTE.DTE)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SDTE));
VCProject prj = (VCProject)dte.Solution.Projects.Item(1).Object;
VCFilter filter = prj.AddFilter("Custom Filter");
filter.AddFile("D:\\path\\File.h");
prj.Save();

Also you need to add Reference to Microsoft.VisualStudio.VCProjectEngine.

Другие советы

Usually VS 2010 has a separate file for filters: YourProject.vcxproj.filters. You can write a script to add stuff you want in this file. But I do not know if everything will work fine without problems.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top