Msbuild 为什么我的目标没有实现?

Msbuild 为什么我的目标没有实现?,msbuild,msbuild-target,Msbuild,Msbuild Target,我将以下目标文件导入到我的.csproj文件中,其中一个目标(AfterAddPostAction)从未触发。为什么不呢? (很抱歉,它太冗长了,但是MSBuild在抽象方面很糟糕,并且CallTask在包含CallTask元素的目标中没有看到设置的属性值。) %WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe C:\Users\Admin\Documents\GitHub\powershell脚本\ $(脚本路径)ProjectSn

我将以下目标文件导入到我的
.csproj
文件中,其中一个目标(AfterAddPostAction)从未触发。为什么不呢? (很抱歉,它太冗长了,但是MSBuild在抽象方面很糟糕,并且CallTask在包含CallTask元素的目标中没有看到设置的属性值。)


%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
C:\Users\Admin\Documents\GitHub\powershell脚本\
$(脚本路径)ProjectSnapShot.ps1
$(脚本路径)postAction-BeforePublish.ps1
-非交互-执行策略不受限制
“&;{&;'$(脚本路径)'}”
AfterClean$(ApplicationVersion).log
.\Logs\$(日志文件)
“{apos;$(LogState)}”
BeforeBuild$(ApplicationVersion).log
.\Logs\$(日志文件)
“{apos;$(LogState)}”
AfterBuild$(ApplicationVersion).log
.\Logs\$(日志文件)
“{apos;$(LogState)}”
BeforePublish$(ApplicationVersion).log
.\Logs\$(日志文件)
“{apos;$(LogState)}”
FileCopyPDA.FileCopyPDA
“(&;&;&;'$(数据定位)'$(数据定位)'$(数据定位)'$(配置)}”
AddPostAction$(ApplicationVersion).log
.\Logs\$(日志文件)
AfterAddPostAction$(ApplicationVersion).log
.\Logs\$(日志文件)
“{apos;$(LogState)}”
AfterPublish$(ApplicationVersion).log
.\Logs\$(日志文件)
“{apos;$(LogState)}”

DependsOnTargets
是将任务链接到序列中的主要方法。但是如果您通过
DependsOnTargets
B
依赖于
A
)实现了序列
A->B->C
,并调用target
A
,那么
B
C
将不会执行。但是如果调用
C
,则
A
B
都会执行

相反,具有
AfterTargets
属性中提到的target
A
的目标将在执行
A
后执行


这就是为什么在您的情况下,如果要使用
DependsOnTargets
,那么执行哪个目标很重要。

当日志级别设置为detailed或diagnostics时,msbuild日志文件中有什么内容?我已将其设置为diagnostics actual,而没有提到
afteraddposaction
。连跳都不跳。我发现,
DependsOnTargets
是不够的,但是
AfterTargets
是不够的。我仍然不明白为什么。您作为“主要”目标执行的是哪个目标?现在我看到十几个目标,不清楚它们是如何被调用的。主要问题是我不理解任务是如何链接的。在我意识到使用
AfterTargets
来建立序列后,我还可以。
DependsOnTargets
是将任务链接到序列中的主要方法。但是如果您通过
DependsOnTargets
(B依赖于A)实现了序列
A->B->C
,并在外部调用target
A
,那么B和C将不会执行。但是如果调用C,那么A和B都被执行。
<?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>&quot;&amp; { &amp;&apos;$(ScriptPath)&apos; } &quot;</Arguments>
    </PropertyGroup>
  </Target>

  <Target Name="AfterClean" DependsOnTargets="EstablishLog">
    <PropertyGroup>
      <LogFile >AfterClean$(ApplicationVersion).log</LogFile>
      <LogFile Condition="Exists('$(MSBuildProjectDirectory)\Logs')">.\Logs\$(LogFile)</LogFile>
      <Arguments>&quot;&amp; { &amp;&apos;$(LogState)&apos; } &quot;</Arguments>
    </PropertyGroup>
    <Exec Command="$(PowerShellExe) $(Switches) -command $(Arguments) &gt; $(LogFile)" />
  </Target>

  <Target Name="BeforeBuild" DependsOnTargets="EstablishLog">
    <PropertyGroup>
      <LogFile >BeforeBuild$(ApplicationVersion).log</LogFile>
      <LogFile Condition="Exists('$(MSBuildProjectDirectory)\Logs')">.\Logs\$(LogFile)</LogFile>
      <Arguments>&quot;&amp; { &amp;&apos;$(LogState)&apos; } &quot;</Arguments>
    </PropertyGroup>
    <Exec Command="$(PowerShellExe) $(Switches) -command $(Arguments) &gt; $(LogFile)" />
  </Target>

  <Target Name="AfterBuild" DependsOnTargets="EstablishLog">
    <PropertyGroup>
      <LogFile >AfterBuild$(ApplicationVersion).log</LogFile>
      <LogFile Condition="Exists('$(MSBuildProjectDirectory)\Logs')">.\Logs\$(LogFile)</LogFile>
      <Arguments>&quot;&amp; { &amp;&apos;$(LogState)&apos; } &quot;</Arguments>
    </PropertyGroup>
    <Exec Command="$(PowerShellExe) $(Switches) -command $(Arguments) &gt; $(LogFile)" />
  </Target>

  <Target Name="BeforePublish" DependsOnTargets="EstablishLog">
    <PropertyGroup>
      <LogFile >BeforePublish$(ApplicationVersion).log</LogFile>
      <LogFile Condition="Exists('$(MSBuildProjectDirectory)\Logs')">.\Logs\$(LogFile)</LogFile>
      <Arguments>&quot;&amp; { &amp;&apos;$(LogState)&apos; } &quot;</Arguments>
    </PropertyGroup>
    <Exec Command="$(PowerShellExe) $(Switches) -command $(Arguments) &gt; $(LogFile)" />
  </Target>

  <Target Name="AddPostAction" AfterTargets="BeforePublish" DependsOnTargets="EstablishLog">
    <PropertyGroup>
      <PostAction>FileCopyPDA.FileCopyPDA</PostAction>
      <Arguments>&quot;&amp; { &amp;&apos;$(DoPostAction)&apos; &apos;$(PostAction)&apos; $(Configuration)} &quot;</Arguments>
      <LogFile >AddPostAction$(ApplicationVersion).log</LogFile>
      <LogFile Condition="Exists('$(MSBuildProjectDirectory)\Logs')">.\Logs\$(LogFile)</LogFile>
    </PropertyGroup>
    <Exec Command="$(PowerShellExe) $(Switches) -command $(Arguments) &gt; $(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>&quot;&amp; { &amp;&apos;$(LogState)&apos; } &quot;</Arguments>
    </PropertyGroup>
    <Exec Command="$(PowerShellExe) $(Switches) -command $(Arguments) &gt; $(LogFile)" />
  </Target>

  <Target Name="AfterPublish" DependsOnTargets="EstablishLog">
    <PropertyGroup>
      <LogFile >AfterPublish$(ApplicationVersion).log</LogFile>
      <LogFile Condition="Exists('$(MSBuildProjectDirectory)\Logs')">.\Logs\$(LogFile)</LogFile>
      <Arguments>&quot;&amp; { &amp;&apos;$(LogState)&apos; } &quot;</Arguments>
    </PropertyGroup>
    <Exec Command="$(PowerShellExe) $(Switches) -command $(Arguments) &gt; $(LogFile)" />
  </Target>

</Project>