-
-
Notifications
You must be signed in to change notification settings - Fork 59
Comparison with MSBuild
Invoke-Build is designed to be conceptually similar to MSBuild. Of course, they use different languages, PowerShell and XML, and different tools. But build concepts and script structure are almost the same.
MSBuild Invoke-Build
------- ------------
Default project *proj Default script *.build.ps1
InitialTargets The top level script code
DefaultTargets The . or the first task
Properties Script/environment variables
Import Dot-source or invoke
Target Task
Condition -If
Inputs, Outputs -Inputs -Outputs [-Partial]
DependsOnTargets -Jobs, referenced tasks
Tasks -Jobs, script blocks
AfterTargets, BeforeTargets -After, -Before (see notes)
MSBuild targets consist of calls to built-in or external tools. Invoke-Build tasks consist of PowerShell script blocks. Unlike MSBuild, Invoke-Build does not provide numerous tools for scripts, PowerShell does this.
Invoke-Build task jobs combine two MSBuild features: referenced targets and own
target tasks. The parameter Jobs
is a list of task references (analogue of
DependsOnTargets
) and script blocks (analogue of MSBuild tasks). Thus, jobs
define classic MSBuild scenarios (referenced tasks first, own scripts second)
and new scenarios with referenced tasks after or even between script jobs.
Invoke-Build "properties" are usual PowerShell script variables and parameters,
just like MSBuild properties defined in XML scripts (variables) and properties
that come from command lines (parameters). MSBuild also deals with environment
variables using the same syntax. In contrast, Invoke-Build scripts either use
them as $env:Name
or get by the helper property
.
MSBuild lets to ignore some errors and perform actions on errors. Invoke-Build also lets to deal with errors: some tasks are allowed to fail without breaking the build and then downstream tasks can analyse these errors.
Invoke-Build allows definition of new tasks with specific features and new
parameters, not necessarily designed for build scenarios. E.g. check
for
check-lists, repeat
for schedules, test
for testing, and etc. MSBuild
presumably does not directly support definition of new targets.
AfterTargets
and BeforeTargets
of MSBuild targets with Condition
are
always invoked, even if the condition is false. In contract, After
and
Before
of Invoke-Build tasks with If
are not invoked if the condition is
false. In other words, these two Invoke-Build scripts are identical, unlike
equivalent MSBuild scripts:
# script1
task Task1 {...}
task Task2 -If {...} Task1, {...}
# script2
task Task1 -Before Task2 {...}
task Task2 -If {...} {...}
See the task Condition-and-related-targets in Acknowledged.build.ps1.
- Concepts
- Script Tutorial
- Incremental Tasks
- Partial Incremental Tasks
- How Build Works
- Special Variables
- Build Failures
- Build Analysis
- Parallel Builds
- Persistent Builds
- Portable Build Scripts
- Using for Test Automation
- Debugging Tips
- VSCode Tips
Helpers
- Invoke Task from VSCode
- Generate VSCode Tasks
- Invoke Task from ISE
- Resolve MSBuild
- Show Build Trees
- Show Build Graph
- Argument Completers
- Invoke-Build.template
Appendix