20131104 basic msbuild by Anney

23
Msbuild basic Anney

description

basic msbuild by Anney

Transcript of 20131104 basic msbuild by Anney

Page 1: 20131104 basic msbuild by Anney

Msbuild basicAnney

Page 2: 20131104 basic msbuild by Anney

Basic MSBuild Elements

<Project>

Root element

Include one or more target , propertyGroup, itemGroup elements.

<Target>

Include one or more Tasks

<PropertyGroup>

<ItemGroup>

Tasks

Copy

Delete

Message

Page 3: 20131104 basic msbuild by Anney

Extension naming rule

.proj

main 入口 .targets

用於 import

.props

僅放 PropertyGroup

.tasks

自製的 UsingTask

Page 4: 20131104 basic msbuild by Anney

本日練習主題

Copy Files Copy D:\test\MSBuild\MyApp Folder to D:\test\MSBuild\MyApp1

Task: Copy

Delete Files Delete D:\test\MSBuild\MyApp1\*.txt

Task: Delete

Show Files Show D:\test\MSBuild\MyApp1 Files

Task: Message

Task References http://msdn.microsoft.com/en-us/library/vstudio/7z253716.aspx

Page 5: 20131104 basic msbuild by Anney

Copy Task

Page 7: 20131104 basic msbuild by Anney

Delete Task

Page 8: 20131104 basic msbuild by Anney

Target Build Order

Page 9: 20131104 basic msbuild by Anney

Target Build Order

InitialTargets

This Project attribute specifies the targets that will run first, even if targets are specified on the command line or in the DefaultTargets attribute.

DefaultTargets

This Project atttribute specifies which targets are run if a target is not specified explicitly on the command line.

DependsOnTargets

This Target attribute specifies targets that must run before this target can run.

BeforeTargets and AfterTargets

These Target attributes specify that this target should run before or after the specified targets.

Page 10: 20131104 basic msbuild by Anney

Demo - InitialTargets

Page 11: 20131104 basic msbuild by Anney

Demo – InitialTargets(2)

Page 12: 20131104 basic msbuild by Anney

Demo – InitialTargets(3)

Page 13: 20131104 basic msbuild by Anney

Demo – DefaultTargets

Page 14: 20131104 basic msbuild by Anney

Demo – DefaultTargets(2)

Page 15: 20131104 basic msbuild by Anney

Demo - DependsOnTargets

Page 16: 20131104 basic msbuild by Anney

Demo – DependsOnTargets(2)

Page 17: 20131104 basic msbuild by Anney

Demo – DependsOnTargets(2)

Page 18: 20131104 basic msbuild by Anney

Demo –BeforeTargets

Page 19: 20131104 basic msbuild by Anney

Demo – AfterTargets

Page 20: 20131104 basic msbuild by Anney

Demo –BeforeTargets and AfterTargets

Page 21: 20131104 basic msbuild by Anney

Determining the Target Build Order

InitialTargets targets are run.

Targets specified on the command line by the /target switch are run. If you specify no targets on the command line, then the DefaultTargets targets are run. If neither is present, then the first target encountered is run.

The Condition attribute of the target is evaluated. If the Condition attribute is present and evaluates to false, the target isn't executed and has no further effect on the build.

Before a target is executed, its DependsOnTargets targets are run.

Before a target is executed, any target that lists it in a BeforeTargets attribute is run.

Before a target is executed, its Inputs attribute and Outputs attribute are compared. If MSBuild determines that any output files are out of date with respect to the corresponding input file or files, then MSBuild executes the target. Otherwise, MSBuild skips the target.

After a target is executed or skipped, any target that lists it in an AfterTargets attribute is run.

Page 23: 20131104 basic msbuild by Anney

~ THE END ~