Udostępnij za pośrednictwem


Build tips of TeamBuild scripts

 

  • MS Build evaluates the condition of the target first and then do the dependency check. For example, in the mentioned proj file, target "B" will never be invoked.

 <Target Name="A"
Condition="'false'= ='true'"
DependsOnTargets="B">
<Message Text="A"/>
</Target>

  <Target Name="B">
<Message Text="B"/>
</Target>

  • Calling msbuild task inside the your proj file will invoke a new process. The child process (of msbuild task) will not inherit all the properties from the parent process. If you want to reuse the properties, you need to explicitly pass them using "Properties" tag of the task.
  • You can split the itemgroups based on attributes using CreateItem task.

  <ItemGroup>
<ResxFile Include="dir1\Resources.resx"/>
<ResxFile Include="dir2\Resources.resx">
<OutputResource>dir2\objd\ClientResources.resources</OutputResource>
</ResxFile>
</ItemGroup>

  <Target Name="SplitResourcesByOutputAttribute">
<CreateItem Include="@(ResxFile)" Condition="'%(ResxFile.OutputResource)'= =''">
<Output TaskParameter="Include" ItemName="ResxFilesWithoutAttribute"/>
</CreateItem>
<CreateItem Include="@(ResxFile)" Condition="'%(ResxFile.OutputResource)'!=''">
<Output TaskParameter="Include" ItemName="ResxFileWithAttribute"/>
</CreateItem>
</Target>