我将以下目标文件导入到我的<?xml version="1.0" encoding="Windows-1252"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="EstablishLog">
<MakeDir Condition="!Exists('$(MSBuildProjectDirectory)\Logs')" Directories=".\Logs"/>
<PropertyGroup>
<PowerShellExe Condition=" '$(PowerShellExe)'=='' ">%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe</PowerShellExe>
<ScriptPath Condition=" '$(ScriptPath)'=='' ">C:\Users\Admin\Documents\GitHub\powershell-scripts\</ScriptPath>
<LogState>$(ScriptPath)ProjectSnapShot.ps1</LogState>
<DoPostAction>$(ScriptPath)postAction-BeforePublish.ps1</DoPostAction>
<Switches>-NonInteractive -executionpolicy Unrestricted</Switches>
<Arguments>"& { &'$(ScriptPath)' } "</Arguments>
</PropertyGroup>
</Target>
<Target Name="AfterClean" DependsOnTargets="EstablishLog">
<PropertyGroup>
<LogFile >AfterClean$(ApplicationVersion).log</LogFile>
<LogFile Condition="Exists('$(MSBuildProjectDirectory)\Logs')">.\Logs\$(LogFile)</LogFile>
<Arguments>"& { &'$(LogState)' } "</Arguments>
</PropertyGroup>
<Exec Command="$(PowerShellExe) $(Switches) -command $(Arguments) > $(LogFile)" />
</Target>
<Target Name="BeforeBuild" DependsOnTargets="EstablishLog">
<PropertyGroup>
<LogFile >BeforeBuild$(ApplicationVersion).log</LogFile>
<LogFile Condition="Exists('$(MSBuildProjectDirectory)\Logs')">.\Logs\$(LogFile)</LogFile>
<Arguments>"& { &'$(LogState)' } "</Arguments>
</PropertyGroup>
<Exec Command="$(PowerShellExe) $(Switches) -command $(Arguments) > $(LogFile)" />
</Target>
<Target Name="AfterBuild" DependsOnTargets="EstablishLog">
<PropertyGroup>
<LogFile >AfterBuild$(ApplicationVersion).log</LogFile>
<LogFile Condition="Exists('$(MSBuildProjectDirectory)\Logs')">.\Logs\$(LogFile)</LogFile>
<Arguments>"& { &'$(LogState)' } "</Arguments>
</PropertyGroup>
<Exec Command="$(PowerShellExe) $(Switches) -command $(Arguments) > $(LogFile)" />
</Target>
<Target Name="BeforePublish" DependsOnTargets="EstablishLog">
<PropertyGroup>
<LogFile >BeforePublish$(ApplicationVersion).log</LogFile>
<LogFile Condition="Exists('$(MSBuildProjectDirectory)\Logs')">.\Logs\$(LogFile)</LogFile>
<Arguments>"& { &'$(LogState)' } "</Arguments>
</PropertyGroup>
<Exec Command="$(PowerShellExe) $(Switches) -command $(Arguments) > $(LogFile)" />
</Target>
<Target Name="AddPostAction" AfterTargets="BeforePublish" DependsOnTargets="EstablishLog">
<PropertyGroup>
<PostAction>FileCopyPDA.FileCopyPDA</PostAction>
<Arguments>"& { &'$(DoPostAction)' '$(PostAction)' $(Configuration)} "</Arguments>
<LogFile >AddPostAction$(ApplicationVersion).log</LogFile>
<LogFile Condition="Exists('$(MSBuildProjectDirectory)\Logs')">.\Logs\$(LogFile)</LogFile>
</PropertyGroup>
<Exec Command="$(PowerShellExe) $(Switches) -command $(Arguments) > $(LogFile)" />
</Target>
<!--This one is never called-->
<Target Name="AfterAddPostAction" DependsOnTargets="EstablishLog;AddPostAction">
<PropertyGroup>
<LogFile >AfterAddPostAction$(ApplicationVersion).log</LogFile>
<LogFile Condition="Exists('$(MSBuildProjectDirectory)\Logs')">.\Logs\$(LogFile)</LogFile>
<Arguments>"& { &'$(LogState)' } "</Arguments>
</PropertyGroup>
<Exec Command="$(PowerShellExe) $(Switches) -command $(Arguments) > $(LogFile)" />
</Target>
<Target Name="AfterPublish" DependsOnTargets="EstablishLog">
<PropertyGroup>
<LogFile >AfterPublish$(ApplicationVersion).log</LogFile>
<LogFile Condition="Exists('$(MSBuildProjectDirectory)\Logs')">.\Logs\$(LogFile)</LogFile>
<Arguments>"& { &'$(LogState)' } "</Arguments>
</PropertyGroup>
<Exec Command="$(PowerShellExe) $(Switches) -command $(Arguments) > $(LogFile)" />
</Target>
</Project>
文件中,其中一个目标(AfterAddPostAction)从未触发。为什么不?
(对不起,它是如此冗长,但MSBuild在抽象时很糟糕,CallTask没有看到在包含CallTask元素的Target中设置的属性值。)
{{1}}
答案 0 :(得分:2)
DependsOnTargets
是将任务链接到序列中的主要方式。但是,如果您通过A->B->C
实施了序列DependsOnTargets
(B
取决于A
)并调用目标A
,那么B
和{{1将不会被执行。但是,如果您致电C
,则C
和A
都会被执行。
相反,B
属性中提到的具有目标A
的目标将在AfterTargets
执行后执行。
这就是为什么在您的情况下,如果您想使用A
,执行哪个目标非常重要。