Comments (6)
Looks like the conditional in task Build2 is evaluated before invoking task
Build1 even though Build2 depends on Build1. Is this by design?
Yes, this is by design that a condition is evaluated first, that is before
referenced tasks.
The whole idea is that if a condition evaluates to false then the task and
its references are not invoked.
Let's take a look at the similar MSBuild example:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Test" Condition="Exists ('z.tmp')" DependsOnTargets="Target1">
<Message Text="In Test"/>
</Target>
<Target Name="Target1">
<Message Text="In Target1"/>
<Copy SourceFiles="z.txt" DestinationFiles="z.tmp"/>
</Target>
</Project>
Example explained:
Test
depends onTarget1
.Target1
is supposed to createz.tmp
.Test
is invoked only ifz.tmp
exists.- Deadlock...
That means MSBuild evaluates conditions before referenced targets.
And Invoke-Build evaluates conditions before referenced tasks.
from invoke-build.
All in all, I think we can close the issue.
UPDATE: see the next comment, though...
Could you describe your real case? I am sure we can find some suitable solution together.
A side note (ignore it if your choice is deliberate). Parameters Before
and After
are designed for special cases, normally when we cannot define references explicitly, e.g. for imported tasks. These parameters can be used in other cases, too, this is legit. I just think that scripts with excessive Before
and After
are rather difficult to understand.
from invoke-build.
I have just found some weird difference between MSBuild and Invoke-Build. But
even with this difference we can see that the condition is evaluated before
other tasks are invoked.
Example is similar to the above but instead of DependsOnTargets="Target1"
on Test
we use BeforeTargets="Test"
on Target1
.
In Invoke-Build, such a swap makes no difference (except the order of some tasks).
In MSBuild, this swap makes Target1
invoked. But the condition is still checked before
and, as a result, the target Test
is actually skipped.
Given we have z.txt
and we do not have z.tmp
in the script directory,
invoke this MSBuild script:
We can see
- Target "Test" skipped, due to false condition.
- We can see
In Target1
, it is invoked - We cannot see
In Test
, it is skipped, even though at this point its condition would get true.
In other words, in Invoke-Build (unlike in MSBuild) these two scripts are equivalent:
# script1
task Build1 {...}
task Build2 -If {...} Build1, {...}
# script2
task Build1 -Before Build2 {...}
task Build2 -If {...} {...}
This is by design and I think it is correct to keep it this way.
I will mention the difference at Comparison-with-MSBuild.
But even with this difference, both MSBuild and Invoke-Build evaluate
conditions before other involved tasks/targets.
from invoke-build.
To your example.
- Here it is (not working as we want):
task buildA -before BuildB,BuildC { $script:invokeBuildB = $true } # or $false
task buildB -if {$script:invokeBuildB} -Before BuildD { }
task buildC -if {!$script:invokeBuildB} -Before BuildD { }
task BuildD { }
- It is identical to (still not working as we want)
task buildA { $script:invokeBuildB = $true } # or $false
task buildB -if {$script:invokeBuildB} buildA, { }
task buildC -if {!$script:invokeBuildB} buildA, { }
task buildD buildB, buildC, { }
- This works as we want
task buildA { $script:invokeBuildB = $true } # or $false
task buildB buildA, {
if ($script:invokeBuildB) { } else { }
}
task buildD buildB, { }
If (3) is not suitable, please tell why and we will find something else.
In other words, as far as one and only one of the tasks B and C is invoked after A, then logically we do not have two tasks. We have one task "do A and process its results". That is what we do in (3).
from invoke-build.
@nightroman Thanks for the detailed explanation! I understand the rationale behind the behavior now. I was playing with invokebuild and was wondering about the situation for which I created the issue. As of now I do not have a concrete situation where I would need this. Thanks again!
from invoke-build.
@kapilmb No problem! It was useful to look at this again. In particular, a not yet known difference between MSBuild and IB was found. I documented it in Comparison-with-MSBuild. I do not know what scenarios are covered by MSBuild and how useful they are. The IB's way looks practical and convenient.
from invoke-build.
Related Issues (20)
- Amend output on task errors.
- Reusing or sharing tasks HOT 5
- ib.cmd ? ignores a specified file
- vscode outline view: no symbols found in document HOT 2
- Different module and package versions HOT 2
- Parallel execution based on dependency tree HOT 2
- invoke-build discovery fails in powershell container HOT 3
- Please consider adding -Computername and -Session parameter to Task HOT 8
- GitHub action output is not colored
- Color and formatting text in Azure DevOps Pipelines HOT 8
- Use-BuildEnv should make parameters mandatory
- Invoke-BuildExec spitting out service principal secret as current directory HOT 6
- Exec doesn't work well with forward slash arguments HOT 7
- Use `[System.Management.Automation.Cmdlet]::CommonParameters` to get the names of all common parameters HOT 3
- Task condition does not work HOT 8
- Build-Parallel writes only to Output stream HOT 7
- property 'File' cannot be found on this object HOT 17
- Do not wrap internal errors in Resolve-MSBuild
- Fix cryptic errors on unknown parameters
- Invoke-BuildExec should pass the original stderr error to the thrown terminating error HOT 38
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from invoke-build.