简体   繁体   English

你如何调用被覆盖的MSBuild目标

[英]How do you call an overridden MSBuild target

In MSBuild you can override a <Target /> from another file in your own. 在MSBuild中,您可以覆盖自己的另一个文件中的<Target /> For example the AfterBuild target included in Microsoft.Common.targets file simply by defining your own Target with the same name: 例如, Microsoft.Common.targets文件中包含的AfterBuild目标只需通过定义具有相同名称的自己的Target:

<Target Name="AfterBuild">
    <!-- Do something different -->
</TargetName>

You'll see a note like this: 你会看到这样一个音符:

Overriding target "AfterBuild" in project "C:\\Windows\\Microsoft.NET\\Framework\\v3.5\\Microsoft.Common.targets" with target "AfterBuild" from project "XXXXX". 在项目“XXXXX”中使用目标“AfterBuild”覆盖项目“C:\\ Windows \\ Microsoft.NET \\ Framework \\ v3.5 \\ Microsoft.Common.targets”中的目标“AfterBuild”。

Is there any way to call the original AfterBuild target? 有没有办法调用原始的AfterBuild目标?

I'd like to do this to instrument certain complex default Targets and then execute the original behavior. 我想这样做来检测某些复杂的默认目标,然后执行原始行为。 Many targets like Build expose a BuildDependsOn property that can be used for this. 像Build这样的许多目标暴露了可用于此的BuildDependsOn属性。 Many others do not - and I'd like to override them without completely duplicating their content. 许多其他人没有 - 我想在不完全复制其内容的情况下覆盖它们。

When an MSBuild script is processed it will also process the imported files. 处理MSBuild脚本时,它还将处理导入的文件。 The result will be a single in memory canonical representation of the entire script. 结果将是整个脚本的单个内存规范表示。 When a target is encountered that already exists the previous definition is discarded, therefore it is not possible to call the original target. 当遇到已存在的目标时,先前的定义将被丢弃,因此无法调用原始目标。

Sayed Ibrahim Hashimi Sayed Ibrahim Hashimi

My Book: Inside the Microsoft Build Engine : Using MSBuild and Team Foundation Build 我的书: Microsoft Build Engine内部:使用MSBuild和Team Foundation Build

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM