MSBuild is a platform that Microsoft provides to build applications that you can use to control and process your software engineering through an XML configuration file. It's also integrated into VS, and it doesn't depend on vs.
The constituent elements of an XML configuration (Schema):
Property
Item
Task
Goal
Property:
< PropertyGroup > < AssemblyName > MSBuildSample</AssemblyName> <OutputPath >bin\</OutputPath> </PropertyGroup >
Item
< ItemGroup > < Include= "HelloWorld.cs"/> </ItemGroup >
Task:
<directories= "$ (OutputPath)" Condition= "! Exists (' $ (OutputPath) ') "/> <Sources=" @ (Compile) " outputassembly= "$ (OutputPath) $ (AssemblyName). exe"/>
Goal: The goal is to combine some tasks in order
<target name= "Build" Span style= "color: #0000ff;" >> <makedir = "$ (OutputPath)" Condition="! Exists (' $ (OutputPath) ') "/> <CSC sources= "@ (Compile)" Outputassembly=" $ (OutputPath) $ (AssemblyName). exe " Span style= "color: #0000ff;" >/> </target
Here is one of the simplest XML Schema files on MSDN:
<Projectxmlns= "http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <CompileInclude= "HelloWorld.cs" /> </ItemGroup> <TargetName= "Build"> <CSCSources= "@ (Compile)"/> </Target></Project>
The file compiles the HelloWorld.cs file through a task.
The following is a simple example of building a C/S architecture application:
XML file-defined properties:
<PropertyGroup> <OutDir>Output</OutDir> <Outserverdir>$ (OutDir) server</Outserverdir> <Outclientdir>$ (OutDir) client</Outclientdir> <Solutionfile>.. \xx\ your project document. sln</Solutionfile> <Serverdir>xx\xx\ Project compiled Bin\server directory</Serverdir> <Clientdir>xx\xx\ Project compiled bin\client directory</Clientdir></PropertyGroup>
An XML file defines the item:
< ItemGroup > < Include= "$ (serverdir) \**\*.*" Exclude= "File definition you want to exclude"/> <Include= "$ (clientdir) \**\*.*" Exclude= " You want to exclude the file definition "/></ItemGroup>
A list of tasks defined by the XML file:
- Clean
- Init
- Build
- Relesase
<TargetName= "clean"> <RemoveDirDirectories= "$ (OutDir)"/> </Target> <TargetName= "Init"DependsOnTargets= "clean"> <MakeDirDirectories= "$ (OutDir)"/> <MakeDirDirectories= "$ (outserverdir)"/> <MakeDirDirectories= "$ (outclientdir)"/> </Target> <TargetName= "Build"DependsOnTargets= "Init"> <MSBuildProjects= "$ (solutionfile)"Targets= "Rebuild"Properties= "Configuration=release"/> </Target> <TargetName= "CopyFiles"DependsOnTargets= "Build"> <CopySourceFiles= "@ (serverdirfiles)"DestinationFiles= "@ (serverdirfiles-> ' $ (outserverdir) \% (recursivedir)% (Filename)% (Extension) ')"/> <CopySourceFiles= "@ (clientdirfiles)"DestinationFiles= "@ (clientdirfiles-> ' $ (outclientdir) \% (recursivedir)% (Filename)% (Extension) ')"/> </Target>
Summary of the above several fragments:
<ProjectDefaultTargets= "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 document. sln</Solutionfile> <Serverdir>Xx\xx\ Project compiled Bin\server directory</Serverdir> <Clientdir>Xx\xx\ Project compiled bin\client directory</Clientdir> </PropertyGroup> <ItemGroup> <ServerdirfilesInclude= "$ (serverdir) \**\*.*"/> <ClientdirfilesInclude= "$ (clientdir) \**\*.*"/> </ItemGroup> <TargetName= "clean"> <RemoveDirDirectories= "$ (OutDir)"/> </Target> <TargetName= "Init"DependsOnTargets= "clean"> <MakeDirDirectories= "$ (OutDir)"/> <MakeDirDirectories= "$ (outserverdir)"/> <MakeDirDirectories= "$ (outclientdir)"/> </Target> <TargetName= "Build"DependsOnTargets= "Init"> <MSBuildProjects= "$ (solutionfile)"Targets= "Rebuild"Properties= "Configuration=release"/> </Target> <TargetName= "CopyFiles"DependsOnTargets= "Build"> <CopySourceFiles= "@ (serverdirfiles)"DestinationFiles= "@ (serverdirfiles-> ' $ (outserverdir) \% (recursivedir)% (Filename)% (Extension) ')"/> <CopySourceFiles= "@ (clientdirfiles)"DestinationFiles= "@ (clientdirfiles-> ' $ (outclientdir) \% (recursivedir)% (Filename)% (Extension) ')"/> </Target></Project>
View Code
You can write a batch command when using this msbuild XML file:
@echo off %SystemRoot%\microsoft. NET\framework\v2.0.50727\msbuild build.xml/nologo/v: MPause
Building Apps with MSBuild