标签:
msbuild是微软提供的一个用于生成应用程序的平台,你可以通过一个xml配置文件来控制和处理你的软件工程。它也集成到了vs里面,它不依赖于vs。
xml配置(架构)的组成元素:
属性
项
任务
目标
<PropertyGroup> <AssemblyName>MSBuildSample</AssemblyName> <OutputPath>Bin\</OutputPath> </PropertyGroup>
<ItemGroup> <Compile Include="helloworld.cs" /> </ItemGroup>
<MakeDir Directories="$(OutputPath)" Condition="!Exists(‘$(OutputPath)‘)" /> <Csc Sources="@(Compile)" OutputAssembly="$(OutputPath)$(AssemblyName).exe" />
<Target Name="Build">
<MakeDir Directories="$(OutputPath)" Condition="!Exists(‘$(OutputPath)‘)" />
<Csc Sources="@(Compile)" OutputAssembly="$(OutputPath)$(AssemblyName).exe" />
</Target>
下面是msdn上面一个最简单的xml构架文件:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <Compile Include="helloworld.cs" /> </ItemGroup> <Target Name="Build"> <Csc Sources="@(Compile)"/> </Target> </Project>
该文件通过一个任务编译helloworld.cs文件。
下面是一个完整的构建一个c/s架构应用程序的简单示例:
<PropertyGroup> <OutDir>output</OutDir> <OutServerDir>$(OutDir)server</OutServerDir> <OutClientDir>$(OutDir)client</OutClientDir> <SolutionFile>..\xx\你的工程文件.sln</SolutionFile> <ServerDir>xx\xx\工程编译后bin\server目录</ServerDir> <ClientDir>xx\xx\工程编译后bin\client目录</ClientDir> </PropertyGroup>
<ItemGroup> <ServerDirFiles Include="$(ServerDir)\**\*.*" Exclude="你要排除的文件定义"/> <ClientDirFiles Include="$(ClientDir)\**\*.*" Exclude="你要排除的文件定义"/> </ItemGroup>
<Target Name="Clean"> <RemoveDir Directories="$(OutDir)"/> </Target> <Target Name="Init" DependsOnTargets="Clean"> <MakeDir Directories="$(OutDir)"/> <MakeDir Directories="$(OutServerDir)"/> <MakeDir Directories="$(OutClientDir)"/> </Target> <Target Name="Build" DependsOnTargets="Init"> <MSBuild Projects="$(SolutionFile)" Targets="Rebuild" Properties="Configuration=Release"/> </Target> <Target Name="CopyFiles" DependsOnTargets="Build"> <Copy SourceFiles="@(ServerDirFiles)" DestinationFiles="@(ServerDirFiles->‘$(OutServerDir)\%(RecursiveDir)%(Filename)%(Extension)‘)"/> <Copy SourceFiles="@(ClientDirFiles)" DestinationFiles="@(ClientDirFiles->‘$(OutClientDir)\%(RecursiveDir)%(Filename)%(Extension)‘)"/> </Target>
<Project DefaultTargets="CopyFiles" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <OutDir>output</OutDir> <OutServerDir>$(OutDir)server</OutServerDir> <OutClientDir>$(OutDir)client</OutClientDir> <SolutionFile>..\xx\你的工程文件.sln</SolutionFile> <ServerDir>xx\xx\工程编译后bin\server目录</ServerDir> <ClientDir>xx\xx\工程编译后bin\client目录</ClientDir> </PropertyGroup> <ItemGroup> <ServerDirFiles Include="$(ServerDir)\**\*.*"/> <ClientDirFiles Include="$(ClientDir)\**\*.*"/> </ItemGroup> <Target Name="Clean"> <RemoveDir Directories="$(OutDir)"/> </Target> <Target Name="Init" DependsOnTargets="Clean"> <MakeDir Directories="$(OutDir)"/> <MakeDir Directories="$(OutServerDir)"/> <MakeDir Directories="$(OutClientDir)"/> </Target> <Target Name="Build" DependsOnTargets="Init"> <MSBuild Projects="$(SolutionFile)" Targets="Rebuild" Properties="Configuration=Release"/> </Target> <Target Name="CopyFiles" DependsOnTargets="Build"> <Copy SourceFiles="@(ServerDirFiles)" DestinationFiles="@(ServerDirFiles->‘$(OutServerDir)\%(RecursiveDir)%(Filename)%(Extension)‘)"/> <Copy SourceFiles="@(ClientDirFiles)" DestinationFiles="@(ClientDirFiles->‘$(OutClientDir)\%(RecursiveDir)%(Filename)%(Extension)‘)"/> </Target> </Project>
在使用这个msbuild xml文件的时候你可以写一个批处理命令:
@echo off %SystemRoot%\Microsoft.NET\Framework\v2.0.50727\msbuild build.xml /nologo /v:m pause
标签:
原文地址:http://www.cnblogs.com/songdaren/p/4585659.html