MSBuild Conditional Exec?

I create various projects using the <MSBuild Projects = "markup ... Then I launch some command line tools after creating the project.

eg

<Target Name="Name"> <MSBuild Projects="" /> <Exec Command="" /> </Target> 

I notice that the project is built as needed and gets the following result when you run the build script: "Skip the target" CoreCompile "because all output files are updated." This is great, but how do I get my <Exec ... commands to use the same condition so that they are executed only when necessary?

Update: I implemented the gregmac suggestion, but it still executes the command independently. This is what I have now:

 <Target Name="Name"> <MSBuild Projects=""> <Output TaskParameter="TargetOutputs" ItemName="AssembliesBuiltByChildProjects" /> </MSBuild> <Exec Command="" Condition="'@(AssembliesBuiltByChildProjects)'!=''" /> 

Any additional help is greatly appreciated. This is a bit for me.

Thanks for any advice.

Alan

+1
post conditional build msbuild
source share
3 answers

I managed to find a solution that suits my needs, although this may not be the optimal solution.

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

Thanks Alan

0
source share

You should 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
source share

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

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

... then you only need to add the 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 CoreCompile target Microsoft.[CSharp|VisualBasic][.Core].targets (the file name depends on the language and version of MSBuild / Visual Studio).

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

So, if you specify the target name in the TargetsTriggeredByCompilation property, your target will be launched if CoreCompile running - and your target will not be launched if CoreCompile is skipped (for example, at the moment regarding the code).

0
source share

All Articles