Use msbuild to build an application and msbuild to build an application
Msbuild is a platform provided by Microsoft for generating applications. You can control and process your software projects through an xml configuration file. It is also integrated into vs, which does not depend on.
Elements of xml configuration (Architecture:
Attribute
Item
Task
Target
Attribute:
<PropertyGroup> <AssemblyName>MSBuildSample</AssemblyName> <OutputPath>Bin\</OutputPath> </PropertyGroup>
Item:
<ItemGroup> <Compile Include="helloworld.cs" /> </ItemGroup>
Task:
<MakeDir Directories="$(OutputPath)" Condition="!Exists('$(OutputPath)')" /> <Csc Sources="@(Compile)" OutputAssembly="$(OutputPath)$(AssemblyName).exe" />
Objective: To combine tasks in sequence
<Target Name="Build"> <MakeDir Directories="$(OutputPath)" Condition="!Exists('$(OutputPath)')" /> <Csc Sources="@(Compile)" OutputAssembly="$(OutputPath)$(AssemblyName).exe" /> </Target>
The following is the simplest xml architecture file on msdn:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <Compile Include="helloworld.cs" /> </ItemGroup> <Target Name="Build"> <Csc Sources="@(Compile)"/> </Target></Project>
Compile the helloworld. cs file using a task.
The following is a simple example of a complete c/s architecture application:
Attributes defined by the xml file:
<PropertyGroup> <OutDir> output </OutDir> <OutServerDir >$ (OutDir) server </OutServerDir> <OutClientDir >$ (OutDir) client </OutClientDir> <SolutionFile> .. \ xx \ your project file. sln </SolutionFile> <ServerDir> xx \ bin \ server Directory after project compilation </ServerDir> <ClientDir> xx \ bin \ client Directory after project compilation </ClientDir> </PropertyGroup>
Items defined in the xml file:
<ItemGroup> <ServerDirFiles Include = "$ (ServerDir )\**\*. * "Exclude =" definition of the file to be excluded "/> <ClientDirFiles Include =" $ (ClientDir )\**\*. * "Exclude =" definition of the file to be excluded "/> </ItemGroup>
Task list defined by the xml file:
<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>
Summary of the above fragments: <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 \ your project file. sln </SolutionFile> <ServerDir> xx \ bin \ server Directory after project compilation </ServerDir> <ClientDir> xx \ bin \ client Directory after project compilation </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>View Code
When using this msbuild xml file, you can write a batch processing command:
@echo off%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\msbuild build.xml /nologo /v:mpause