1.属性 PropertyGroup
$符号调用,可以在XML中传参数,也可以在命令行中传入参数。
D:msbuild est3.msbuild
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <msginfo>hello world</msginfo> </PropertyGroup> <Target Name="yefengGreeting"> <Message Text="$(msginfo)"></Message> <Message Text="$(ProjectName)"></Message> </Target> </Project>
D:msbuild>msbuild test3.msbuild /p:ProjectName=kfsmqoo
2.目标任务 Target
默认编译第一个目标任务。
参数:/t:Target1;Target2 编译多个目标任务
D:msbuildTarget.msbuild
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <msginfo>Target1</msginfo> </PropertyGroup> <Target Name="Target1"> <Message Text="$(msginfo)"></Message> <Message Text="$(ProjectName)"></Message> </Target> <Target Name="Target2"> <Message Text="Target2"></Message> </Target> </Project>
D:msbuild>msbuild Target.msbuild /t:Target1;Target2
DependsOnTargets 目标任务依赖
D:msbuildTarget.msbuild
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <msginfo>Target1</msginfo> </PropertyGroup> <Target Name="Target3" DependsOnTargets="Target1;Target2"> <Message Text="Target3"></Message> </Target> <Target Name="Target1"> <Message Text="$(msginfo)"></Message> <Message Text="$(ProjectName)"></Message> </Target> <Target Name="Target2"> <Message Text="Target2"></Message> </Target> </Project>
D:msbuild>msbuild Target.msbuild /t:target3;target2;target1
以此执行的是的1,2,3
1,2没有顺序关系,按照XML的从上到下依次执行,3等1,2执行完毕再执行 。结果如下: