Share via


Using $(Inherit) and $(NoInherit)

This topic gives some examples on how to use the $(Inherit) and $(NoInherit) macros.

  • Set the following additional include path (/I) at the project level:

    c:\test
    
  • For a particular file, set the following additional include path:

    c:\test2;c:\mystuff
    
  • Observe the file's Command Line property page. It includes:

    /I"c:\test2" /I"c:\mystuff" /I"c:\test"
    

    This is because there is an implicit $(Inherit) at the end of the file configuration's additional include paths if $(Inherit) is not placed in the list explicitly.

  • However, if you change the file configuration's additional include path to this:

    c:\test2;$(Inherit);c:\mystuff
    

    it will expand to the following on the file's Command Line property page:

    /I"c:\test2" /I"c:\test" /I"c:\mystuff"
    

    Notice that the additional include path from the project configuration is where the $(Inherit) macro was placed. The $(Inherit) macro is used to guide the placement of inherited values that are part of this property. It can go anywhere in the list.

  • If you change the file configuration's additional include path to this:

    $(Inherit);c:\test2;$(Inherit);c:\mystuff
    

    it will expand to the following on the file's Command Line property page:

    /I"c:\test" /I"c:\test2" /I"c:\test" /I"c:\mystuff"
    
  • If you change the file configuration's additional include path to this:

    c:\test2;c:\mystuff;$(NoInherit)
    

    it will expand to the following on the file's Command Line property page:

    /I"c:\test2" /I"c:\mystuff"
    

    Notice that /I"c:\test" from the project configuration is gone. The location of the $(NoInherit) macro has no bearing on how it is used, unlike $(Inherit), which is location-sensitive.

$(NoInherit) takes precedence over $(Inherit). If $(NoInherit) is present, $(Inherit) will be ignored. For example, changing the file configuration's additional include path to this:

c:\test2;$(Inherit);c:\mystuff;$(NoInherit)

will expand it exactly the same as if it was:

c:\test2;c:\mystuff;$(NoInherit)

Use care with $(NoInherit) in the Defines property for tools like the C/C++ compiler or linker; you can cancel the use of project defaults (such as those set by Use of ATL and Use of MFC).

See Also

Other Resources

Macros for Build Commands and Properties