msbuild:在另一个任务使用的任务中设置属性

时间:2019-07-14 16:12:16

标签: msbuild

我想获得git commit id作为预处理程序定义,而没有额外的依赖关系(社区目标)。

为什么RcVerGitHash属性重新评估了我的任务(BeforeGetGitInfoAfterGetGitInfo),而不重新评估了外部任务(RC)?

    <PropertyGroup>
      <RcVerGitHash>RcVerGitHashDefaultValue</RcVerGitHash>
    </PropertyGroup>

    <Target Name="GetGitInfo" BeforeTargets="BeforeResourceCompile">
      <Exec Command="git describe --broken --dirty --long --always" ConsoleToMsBuild="true"
          IgnoreExitCode="true" ContinueOnError="true">
        <Output TaskParameter="ConsoleOutput" PropertyName="RcVerGitHash"/>
      </Exec>
      <Message Importance="high" Text="RcVerGitHash: $(RcVerGitHash)"/>
      <PropertyGroup>
        <RcVerGitHash>VER_GITHASH=\"$(RcVerGitHash)\";</RcVerGitHash>
      </PropertyGroup>

      <Message Importance="high" Text="$(RcVerGitHash)"/>

    </Target>

    <Target Name="BeforeGetGitInfo" BeforeTargets="GetGitInfo">
      <Message Importance="high" Text="RcVerGitHash bef: $(RcVerGitHash)"/>
    </Target>

    <Target Name="AfterGetGitInfo" AfterTargets="GetGitInfo">
      <Message Importance="high" Text="RcVerGitHash aft: $(RcVerGitHash)"/>
    </Target>

构建输出:

        RcVerGitHash bef: RcVerGitHashDefaultValue
        ${TAG}-120-g449d6d7-dirty
        RcVerGitHash: ${TAG}-120-g449d6d7-dirty
        VER_GITHASH=\"${TAG}-120-g449d6d7-dirty\";
        RcVerGitHash aft: VER_GITHASH=\"${TAG}-120-g449d6d7-dirty\";

    .... (diagnostic output)

    Target "ResourceCompile" in file "...\v150\Microsoft.CppCommon.targets":
      Set Property: RCToolArchitecture=Native32Bit
      Using "RC" task from assembly "...\v150\Microsoft.Build.CppTasks.Common.dll".
      Task "RC"
        Task Parameter:Source=myres.rc
        Task Parameter:
            PreprocessorDefinitions=
                RcVerGitHashDefaultValue
                _USRDLL
                _DEBUG
        Task Parameter:ResourceOutputFileName=Debug\myres.res
        ....

0 个答案:

没有答案