How can you conditionally run the MSBuild task only when your projects were created?

I want to run the MSBuild task (which signs the / dll executable), but only when the output exe / dll changes. If none of the source files has changed, resulting in recompilation of exe / dll, I do not want the task to be executed.

Although I tried different things for several hours, I can’t understand how to make my target work only if the project was compiled where the output files were changed (in other words, the CoreCompile target was not missed, I think).

+7
msbuild
source share
2 answers

Should be the same as this answer using the TargetOutputs parameter:

<MSBuild Projects="File.sln" > <Output TaskParameter="TargetOutputs" ItemName="AssembliesBuiltByChildProjects" /> </MSBuild> <Message Text="Assemblies built: @(AssembliesBuiltByChildProjects)" /> <!-- just for debug --> <CallTarget Targets="SignExe" Condition="'@(AssembliesBuiltByChildProjects)'!=''" /> 
+2
source share

You can simply do this:

 <PropertyGroup> <TargetsTriggeredByCompilation>DoStuffWithNewlyCompiledAssembly</TargetsTriggeredByCompilation> </PropertyGroup> 

This works because someone smart at Microsoft added the following line at the end of the Microsoft.[CSharp|VisualBasic][.Core].targets 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, because the assembly assembly is already enabled, at the moment with respect to the code).

0
source share

All Articles