How to: Choose the Best Object for Tool Properties

If you are looking for tool properties, try to get them from the object that most closely represents the location where you want the properties. For example, if you want to know the header file name output of Microsoft Interface Definition Language (MIDL), it is more efficient to get this information from a file configuration on the .idl file in question rather than from a project configuration. If you use a project configuration, you will encounter two different problems:

  • The setting at the file level can be different than at the project level.

  • Nothing guarantees that the tool you expect to be applied to the file is the one that is actually applied.

In Visual C++ 5.0 and earlier projects, a custom build step was used instead of MIDL as the tool associated with an IDL or ODL file. You can also apply any file level tool to any file, so file extension guarantees nothing on existing files. Because you must have the closest property container to do proper macro evaluation, you should also use it to get property values.

Note

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. These procedures were developed with the General Development Settings active. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To get a project configuration from a file configuration

  • The following information lets you find the correct objects.

    file = fileCfg.File
    cfgName = fileCfg.Name
    proj = file.Project
    projCfg = proj.Configurations(cfgName)
    

To get a file configuration given a project configuration and file

  • The following information lets you find the correct objects.

    cfgName = projCfg.Name
    fileCfg = file.Configurations(cfgName)
    
  • When accessing tool settings for a file, it is important to do something similar to the following: tool = fileCfg.Tool than tool = projCfg.Tools("VCMidlTool").

    To ensure that you have the tool you expect:

    if (tool.ToolPath == "cl.exe")      
       // You have the C/C++ compiler.
    

See Also

Concepts

Macros in Project System Properties

Other Resources

Visual C++ Extensibility Object Model