MS Build 笔记
//—–MSBuild的执行路径
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
或在Visual Studio 2005 command prompt下直接运行
//——条件的使用
<Configuration Condition=" ‘$(Configuration)’ == ‘’ ">
Debug
</Configuration>
<MakeDir Directories="$(CopyLocation)" Condition="!Exists(’$(CopyLocation)’)"/>
//——显示信息
<Target Name="Hello">
<Message Text="Hello MSBuild" Importance="high"/>
</Target>
//——什么是metadata
一个Item的属性,分为Well-known 和custom
所有的Item都可以使用Well-known的metadata
比如,以下的MyItem 包含了文件file C:\MyProject\Source\Program.cs
<ItemGroup>
<MyItem Include="Source\Program.cs" />
</ItemGroup>
可以使用Well-known metadata %(FullPath)得到
Custon metadata应用范围在当前的project文件中.
使用metadata和使用well-known的语法相同:
%(RelativeDir)
//——MSBuild 特殊字符
使用 %xx 语法对特殊字符进行转义,xx为该字符的ASC码.
//——在 MSBuild Project中使用环境变量
引用环境变量的方法与引用项目文件中声明的变量的方法相同
<FinalOutput>$(BIN_PATH)\MyAssembly.dll</FinalOutput>
//——什么是Transformation
Transformation的语法:
@(ItemName->’TransformationDetails’)
ItemName is the name of the item you are transforming, and the TransformationDetails
can contain raw text, evaluated properties, and metadata references.
比如
<Copy SourceFiles="@(Compile->’%(FullPath)’)"
DestinationFiles="@(Compile->’$(MSBuildProjectDirectory)\$(CopyLocation)\%(RelativeDir)\%(FileName)%(Extension)’)"/>
@(Compile->’%(FullPath)’) 会得到Item Compile的FullPath
//——-清除project 的bin目录
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="CleanAllProjects">
<!– Find all projects in or below the current directory –>
<ItemGroup>
<Projects Include="**\*.*proj" />
</ItemGroup>
<Target Name="CleanAllProjects">
<MSBuild Projects="@(Projects)" Targets="Clean" StopOnFirstFailure="false" ContinueOnError="true">
</MSBuild>
</Target>
</Project>
//——-MSBuild 的Include 文件
这些文件存在于C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\
修改 Microsoft.Common.targets 中的CoreBuildDependsOn
Microsoft.Common.Tasks
//——-使用custom tasks扩展MS build:
1.从Microsoft.Build.Utilities.Task 派生
public class TempFile : Task
{
public override bool Execute()
{
this.tempFilePath = System.IO.Path.GetTempFileName();
return true;
}
}
2.写一个 project 文件
<UsingTask AssemblyFile="$(SharedTasksDir)\Tasks.dll" TaskName="Move"/>
//——-使用custom logger扩展MS build:
[尚待学习…]
参考
Compile Apps Your Way With Custom Tasks For The Microsoft Build Engine
http://msdn.microsoft.com/msdnmag/issues/06/06/InsideMSBuild/default.aspx
