Target – element (MSBuild)Target element (MSBuild)
Obsahuje sadu úloh, které má nástroj MSBuild spustit sekvenčně.Contains a set of tasks for MSBuild to execute sequentially.
<Project> <Target><Project> <Target>
SyntaxSyntax
<Target Name="Target Name"
Inputs="Inputs"
Outputs="Outputs"
Returns="Returns"
KeepDuplicateOutputs="true/false"
BeforeTargets="Targets"
AfterTargets="Targets"
DependsOnTargets="DependentTarget"
Condition="'String A' == 'String B'"
Label="Label">
<Task>... </Task>
<PropertyGroup>... </PropertyGroup>
<ItemGroup>... </ItemGroup>
<OnError... />
</Target>
Atributy a elementyAttributes and elements
Následující části popisují atributy, podřízené prvky a nadřazené prvky.The following sections describe attributes, child elements, and parent elements.
AtributyAttributes
AtributAttribute | PopisDescription |
---|---|
Name |
Požadovaný atribut.Required attribute. Název cíleThe name of the target. Název cíle může obsahovat libovolný znak s výjimkou $@()%*?. .A target name may contain any character except $@()%*?. . |
Condition |
Nepovinný atribut.Optional attribute. Podmínka, která má být vyhodnocena.The condition to be evaluated. Pokud je podmínka vyhodnocena jako false , cíl nespustí tělo cíle nebo žádné cíle, které jsou nastaveny v DependsOnTargets atributu.If the condition evaluates to false , the target will not execute the body of the target or any targets that are set in the DependsOnTargets attribute. Další informace o podmínkách najdete v tématu podmínky.For more information about conditions, see Conditions. |
Inputs |
Nepovinný atribut.Optional attribute. Soubory, které tvoří vstupy do tohoto cíle.The files that form inputs into this target. Několik souborů je oddělených středníky.Multiple files are separated by semicolons. Časová razítka souborů budou porovnána s časovými razítky souborů v Outputs , aby bylo možné zjistit, zda Target je v aktuálním stavu.The timestamps of the files will be compared with the timestamps of files in Outputs to determine whether the Target is up to date. Další informace naleznete v tématu přírůstkové sestavení, Postupy: sestavení přírůstkověa transformace.For more information, see Incremental builds, How to: Build incrementally, and Transforms. |
Outputs |
Nepovinný atribut.Optional attribute. Soubory, které tvoří výstup do tohoto cíle.The files that form outputs into this target. Několik souborů je oddělených středníky.Multiple files are separated by semicolons. Časová razítka souborů budou porovnána s časovými razítky souborů v Inputs , aby bylo možné zjistit, zda Target je v aktuálním stavu.The timestamps of the files will be compared with the timestamps of files in Inputs to determine whether the Target is up to date. Další informace naleznete v tématu přírůstkové sestavení, Postupy: sestavení přírůstkověa transformace.For more information, see Incremental builds, How to: Build incrementally, and Transforms. |
Returns |
Nepovinný atribut.Optional attribute. Sada položek, které budou zpřístupněny pro úlohy, které vyvolávají tento cíl, například úlohy MSBuild.The set of items that will be made available to tasks that invoke this target, for example, MSBuild tasks. Více cílů je odděleno středníky.Multiple targets are separated by semicolons. Pokud cíle v souboru nemají žádné Returns atributy, místo toho se pro tento účel použijí atributy výstupy.If the targets in the file have no Returns attributes, the Outputs attributes are used instead for this purpose. |
KeepDuplicateOutputs |
Volitelný atribut typu Boolean.Optional Boolean attribute. Pokud je true zaznamenáno více odkazů na stejnou položku v cílovém objektu vrátí se.If true , multiple references to the same item in the target's Returns are recorded. Ve výchozím nastavení je tento atribut false .By default, this attribute is false . |
BeforeTargets |
Nepovinný atribut.Optional attribute. Seznam cílových názvů oddělený středníkemA semicolon-separated list of target names. Je-li tento parametr zadán, označuje, že tento cíl bude spuštěn před zadaným cílem nebo cílem.When specified, indicates that this target should run before the specified target or targets. Tím umožníte, aby autor projektu rozšířil existující sadu cílů beze změny přímo.This lets the project author extend an existing set of targets without modifying them directly. Další informace najdete v tématu cílové pořadí sestavení.For more information, see Target build order. |
AfterTargets |
Nepovinný atribut.Optional attribute. Seznam cílových názvů oddělený středníkemA semicolon-separated list of target names. Když se tato parametr zadá, označuje, že se má tento cíl spustit po zadaném cíli nebo cíli.When specified, indicates that this target should run after the specified target or targets. Tím umožníte, aby autor projektu rozšířil existující sadu cílů beze změny přímo.This lets the project author extend an existing set of targets without modifying them directly. Další informace najdete v tématu cílové pořadí sestavení.For more information, see Target build order. |
DependsOnTargets |
Nepovinný atribut.Optional attribute. Cíle, které je třeba provést před provedením tohoto cíle, nebo může dojít k analýze závislostí na nejvyšší úrovni.The targets that must be executed before this target can be executed or top-level dependency analysis can occur. Více cílů je odděleno středníky.Multiple targets are separated by semicolons. |
Label |
Nepovinný atribut.Optional attribute. Identifikátor, který může identifikovat nebo seřadit systémové a uživatelské prvky.An identifier that can identify or order system and user elements. |
Podřízené prvkyChild elements
ElementElement | PopisDescription |
---|---|
ÚkolTask | Vytvoří a spustí instanci úlohy MSBuild.Creates and executes an instance of an MSBuild task. V cíli může být nula nebo více úkolů.There may be zero or more tasks in a target. |
PropertyGroupPropertyGroup | Obsahuje sadu uživatelsky definovaných Property prvků.Contains a set of user-defined Property elements. Počínaje .NET Framework 3,5 Target prvek může obsahovat PropertyGroup elementy.Starting in the .NET Framework 3.5, a Target element may contain PropertyGroup elements. |
ItemGroupItemGroup | Obsahuje sadu uživatelsky definovaných Item prvků.Contains a set of user-defined Item elements. Počínaje .NET Framework 3,5 Target prvek může obsahovat ItemGroup elementy.Starting in the .NET Framework 3.5, a Target element may contain ItemGroup elements. Další informace najdete v tématu položky.For more information, see Items. |
OnErrorOnError | Způsobí, že jeden nebo více cílů bude spuštěno, pokud ContinueOnError je atribut ErrorAndStop (nebo false ) pro neúspěšnou úlohu.Causes one or more targets to execute if the ContinueOnError attribute is ErrorAndStop (or false ) for a failed task. V cíli může být nula nebo více OnError prvků.There may be zero or more OnError elements in a target. Pokud OnError jsou prvky přítomny, musí se jednat o poslední prvky v Target elementu.If OnError elements are present, they must be the last elements in the Target element.Informace o atributu naleznete ContinueOnError v tématu element Task (MSBuild).For information about the ContinueOnError attribute, see Task element (MSBuild). |
Nadřazené prvkyParent elements
ElementElement | PopisDescription |
---|---|
ProjektProject | Požadovaný kořenový element souboru projektu MSBuild.Required root element of an MSBuild project file. |
PoznámkyRemarks
První cíl, který má být spuštěn, je určen v době běhu.The first target to execute is specified at run time. Cíle můžou mít závislosti na jiných cílech.Targets can have dependencies on other targets. Například cíl pro nasazení závisí na cíli pro kompilaci.For example, a target for deployment depends on a target for compilation. Modul MSBuild spouští závislosti v pořadí, ve kterém jsou uvedeny v DependsOnTargets
atributu zleva doprava.The MSBuild engine executes dependencies in the order in which they appear in the DependsOnTargets
attribute, from left to right. Další informace najdete v tématu cíle.For more information, see Targets.
MSBuild je závislý na pořadí importu a poslední definice cíle s konkrétním Name
atributem je použitá definice.MSBuild is import-order dependent, and the last definition of a target with a specific Name
attribute is the definition used.
Cíl se spustí pouze jednou během sestavení, i když na něm závisí více než jeden cíl.A target is only executed once during a build, even if more than one target has a dependency on it.
Pokud je cíl vynechán, protože se jeho Condition
atribut vyhodnocuje false
, může být stále proveden, pokud je vyvolán později v sestavení a jeho atribut je Condition
true
v daném čase vyhodnocen jako.If a target is skipped because its Condition
attribute evaluates to false
, it can still be executed if it is invoked later in the build and its Condition
attribute evaluates to true
at that time.
Před MSBuild 4 Target
vrátily všechny položky, které byly zadány v Outputs
atributu.Before MSBuild 4, Target
returned any items that were specified in the Outputs
attribute. Nástroj MSBuild musel tyto položky zaznamenat v případě, že je požaduje, později v sestavení.To do this, MSBuild had to record these items in case tasks later in the build requested them. Vzhledem k tomu, že neexistuje žádný způsob, jak určit, které cíle obsahovaly výstupy, které by volající vyžadovaly, nástroj MSBuild shromáždil všechny položky ze všech Outputs
vyvolaných Target
s.Because there was no way to indicate which targets had outputs that callers would require, MSBuild accumulated all items from all Outputs
on all invoked Target
s. To vede k škálování problémů pro sestavení, která měla velký počet výstupních položek.This lead to scaling problems for builds that had a large number of output items.
Pokud uživatel určí Returns
u libovolného Target
elementu v projektu, pak pouze ty Target
, které mají Returns
atribut, tyto položky se zaznamenají.If the user specifies a Returns
on any Target
element in a project, then only those Target
s that have a Returns
attribute record those items.
Target
Může obsahovat Outputs
atribut i Returns
atribut.A Target
may contain both an Outputs
attribute and a Returns
attribute. Outputs
se používá s Inputs
k určení, zda je cíl v aktuálním stavu.Outputs
is used with Inputs
to determine whether the target is up-to-date. Returns
, pokud je k dispozici, Přepisuje hodnotu Outputs
k určení, které položky jsou vraceny volajícím.Returns
, if present, overrides the value of Outputs
to determine which items are returned to callers. Pokud není k Returns
Outputs
dispozici, bude zpřístupněna volajícím s výjimkou výše popsaného případu.If Returns
is not present, then Outputs
will be made available to callers except in the case described earlier.
Před tím, než nástroj MSBuild 4 pokaždé, když jsou Target
zahrnuté více odkazů na stejnou položku Outputs
, budou tyto duplicitní položky zaznamenávány.Before MSBuild 4, any time that a Target
included multiple references to the same item in its Outputs
, those duplicate items would be recorded. Ve velmi rozsáhlých sestaveních, která měla velký počet výstupů a mnoho vzájemně závislých projektů, by to znamenalo neplýtvání velkého množství paměti, protože duplicitní položky nebyly žádného použití.In very large builds that had a large number of outputs and many project interdependencies, this would cause a large amount of memory to be wasted because the duplicate items were not of any use. Pokud KeepDuplicateOutputs
je atribut nastaven na true
, jsou tyto duplicity zaznamenávány.When the KeepDuplicateOutputs
attribute is set to true
, these duplicates are recorded.
PříkladExample
Následující příklad kódu ukazuje Target
prvek, který Csc
úlohu spouští.The following code example shows a Target
element that executes the Csc
task.
<Target Name="Compile" DependsOnTargets="Resources" Returns="$(TargetPath)">
<Csc Sources="@(CSFile)"
TargetType="library"
Resources="@(CompiledResources)"
EmitDebugInformation="$(includeDebugInformation)"
References="@(Reference)"
DebugType="$(debuggingType)" >
<Output TaskParameter="OutputAssembly"
ItemName="FinalAssemblyName" />
</Csc>
</Target>