.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
.targetsfile is an XML file with
<Target>nodes that contain MSBuild scripts with lists of tasks to perform.
- You can create, add, enable, or remove
.targetsfiles in a project with the IDE.
You create and add a
.targets file to the project using either menu commands or the Projects Window 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
.targets files are added to the project but not used by it. You enable a
.targets file with the Projects Window, 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> elements directly from disk, the
.targets file must be saved to disk before a Make, Build, or invoking any of its targets.
Target Element in
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 Target Element (MSBuild) (MSDN) for more information on target elements.
.targets file contains valid
<Target> elements, you can invoke those targets using MSBuild from the Project Manager, provided the
.targets file is enabled.
.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 files, which are installed in
C:\Program Files (x86)\Embarcadero\Studio\20.0\bin. You should not modify any
.targets files in this directory, since improper edits might cause the IDE to stop functioning correctly.
- Tip: For more information about
.targetsfiles, see MSBuild .Targets Files (MSDN).