MSBuild conditional Exec?

前端 未结 3 1312
一向
一向 2021-01-06 13:47

I am building various projects using the

E.g



        
相关标签:
3条回答
  • 2021-01-06 13:58

    You should be able to use the TargetOutputs parameter:

    <MSBuild Projects="" >
       <Output TaskParameter="TargetOutputs" ItemName="AssembliesBuiltByChildProjects" />
    </MSBuild>
    <Message Text="Assemblies built: @(AssembliesBuiltByChildProjects)" /> <!-- just for debug -->
    <Exec Command="" Condition="'@(AssembliesBuiltByChildProjects)'!=''" />
    
    0 讨论(0)
  • 2021-01-06 14:05

    If you can add the following to each of your projects:

    <Target Name="DoStuffWithNewlyCompiledAssembly">
        <Exec Command="" />
    </Target>
    

    ... then you only need to add a property:

    <Target Name="Name">
      <MSBuild Projects="" Properties="TargetsTriggeredByCompilation=DoStuffWithNewlyCompiledAssembly" />
    </Target>
    

    This works because someone smart at Microsoft added the following line at the end of the CoreCompile target in Microsoft.[CSharp|VisualBasic][.Core].targets (the file name depends on the language and MSBuild/Visual Studio version).

    <CallTarget Targets="$(TargetsTriggeredByCompilation)" Condition="'$(TargetsTriggeredByCompilation)' != ''"/>
    

    So if you specify a target name in the TargetsTriggeredByCompilation property, your target will run if CoreCompile runs-- and your target will not run if CoreCompile is skipped (e.g. because the output assembly is already up-to-date with respect to the code).

    0 讨论(0)
  • 2021-01-06 14:10

    I did manage to find a solution to fit my needs although it may not be the optimal solution.

    See my answer to my other question here: MSBuild Post-Build

    Thanks, Alan

    0 讨论(0)
提交回复
热议问题