RAD Studio (Common)
ContentsIndex
PreviousUpNext
Targets files

A .targets file is an MSBuild-compliant XML file you can add to a project to allow customizing the build process. A .targets file can have <Target> nodes containing MSBuild scripts.  

You can also add or modify project property values with a .targets file. You can leverage the large variety of MSBuild tasks available in the .NET Framework SDK and on the internet, such as "Zip", "SVNCheckout", and "Mail", or write custom tasks yourself. 

In summary:

  • A .targets file is an XML file with <Target> nodes that contain MSBuild scripts with lists of tasks to perform.
  • You can create, add, enable, or remove .targets files in a project with the IDE.

You create and add a .targets file to the project using either menu commands or the Project Manager context menu. The IDE generates a minimal .targets file containing only the <Project> root node and namespace attribute. You can then add MSBuild scripts inside the <Project> node. 

By default, .targets files are added to the project but not used by it. You enable a .targets file with the Project Manager, which adds the .targets file as an MSBuild <Import> to your project. All .targets files must contain valid MSBuild scripts free of errors. If the file has any errors, you are notified and, if the project references the invalid .targets file, it is disabled and cannot be re-enabled until the errors are corrected. Because MSBuild can only read <Import>s directly from disk, the .targets file must be saved to disk before a Make, Build, or invoking any of its targets.

The target element in the .targets file contains a set of tasks for MSBuild to execute. Here is its format:

<Target Name="Target Name"
        DependsOnTargets="DependentTarget"
        Inputs="Inputs"
        Outputs="Outputs"
        Condition="'String A' == 'String B'">
    <Task>... </Task>
    <OnError... />
</Target>

See http://msdn2.microsoft.com/en-us/library/t50z2hka.aspx for more information on target elements.

When a .targets file contains valid <Target> elements, you can invoke those targets using MSBuild from the Project Manager, provided the .targets file is enabled. 

The .targets file can declare its own properties, targets, and item groups for use by its targets and tasks. It can also refer to properties and item groups in the project file, including those imported from the standard Codegear .targets file in the Windows directory at microsoft.net\Framework\v2.0.xxx\Borland.Cpp.Targets. You should not modify any .targets files in this directory, since improper edits may cause the IDE to stop functioning correctly.

Tip: For more information about .targets files, see http://msdn2.microsoft.com/en-us/library/ms164312.aspx.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!