I have a class library in an SDK style project. It targets several frameworks, e.g.:
<TargetFrameworks>net48;netcoreapp3.1;net5.0-windows;net6.0-windows</TargetFrameworks>
I have a target that I want to run after the builds, e.g.
<Target Name="WriteText" AfterTargets="AfterBuild">
<Exec Command="echo $(TargetFramework)"/> <!-- print out target framework -->
</Target>
If I run dotnet build
, I can see from the console that the command is run after each build. But I want it to be run just once after all builds are done.
How can I make it be run just once after all builds are done?
I know I can work with conditions, so I could put a condition like
Condition="'$(TargetFramework)' == 'net6.0-windows'"
into my target to let it run after a certain framework build. But I need it to run after the LAST build, and which one is the last build? Is it
- the last one in my
<TargetFrameworks>
list? (No.) - always a certain one in my
<TargetFrameworks>
list? (Seems so on my computer, at the moment. But can I be sure of it? What about other computers or future MSBuild versions?)
What I think I need is a way to manipulate a variable during builds, and then put a condition on that variable. Like this:
- There is an int variable
finishedBuilds
that is0
before any build is done. - There is a target that adds
1
tofinishedBuilds
after build. It has no condition, so it is called after each build. - The condition for my desired command is then
Condition="'$(finishedBuilds)' == '4'"
.
Is that possible, and if yes, how?
AfterTargets="DispatchtoInnerBuilds"
. – Fazio