![]() |
![]() |
|||
![]() |
||||
![]() |
![]() |
Visual C++ projects have standard include directories for each configuration / platform, and additional include directories. This article provides the sample code to get the additional include directories from an add-in. To get the standard include directories, see the article HOWTO: Get standard include directories of Visual C++ project from an add-in. More Information To get specific Visual C++ project information from an add-in, you need to add a reference to the Microsoft.VisualStudio.VCProjectEngine.dll assembly. There are specific versions of this assembly for each Visual Studio version:
Once added, you can use the following code to get the additional include directories of each configuration / platform. The add-in, once loaded, shows the additional include directories of the first project of the solution:
using System; using Extensibility; using EnvDTE; using EnvDTE80; using System.Windows.Forms; namespace MyAddin { public class Connect : IDTExtensibility2 { private DTE2 _applicationObject; private AddIn _addInInstance; public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _applicationObject = (DTE2)application; _addInInstance = (AddIn)addInInst; switch (connectMode) { case ext_ConnectMode.ext_cm_Startup: // Do nothing. OnStartupComplete will be called break; case ext_ConnectMode.ext_cm_AfterStartup: InitializeAddIn(); break; } } public void OnStartupComplete(ref Array custom) { InitializeAddIn(); } private void InitializeAddIn() { EnvDTE.Project project; try { project = _applicationObject.Solution.Projects.Item(1); ShowAdditionalIncludeDirectories(project); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void ShowAdditionalIncludeDirectories(EnvDTE.Project project) { Microsoft.VisualStudio.VCProjectEngine.VCProject proj; Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool compilerTool; Microsoft.VisualStudio.VCProjectEngine.IVCCollection toolsCollection; Microsoft.VisualStudio.VCProjectEngine.IVCCollection configurationsCollection; proj = (Microsoft.VisualStudio.VCProjectEngine.VCProject)project.Object; configurationsCollection = (Microsoft.VisualStudio.VCProjectEngine.IVCCollection)proj.Configurations; foreach (Microsoft.VisualStudio.VCProjectEngine.VCConfiguration configuration in configurationsCollection) { toolsCollection = (Microsoft.VisualStudio.VCProjectEngine.IVCCollection)configuration.Tools; foreach (Object toolObject in toolsCollection) { if (toolObject is Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool) { compilerTool = (Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool)toolObject; MessageBox.Show(configuration.Name + ": " + compilerTool.AdditionalIncludeDirectories); break; } } } } public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom) { } public void OnAddInsUpdate(ref Array custom) { } public void OnBeginShutdown(ref Array custom) { } } } Related articles Follow @VSExtensibility |
Copyright © 2000-2021 MZTools Software. All Rights Reserved. Legal Notice |