MSBuild is very powerful language for automating build process but as every computer thing it could be confusing.
So for a start this should work as Visual Studio solution files (*.sln/*.proj) files are valid MSBuild files:
MSBuild MySolution.sln
So for more script-like example this can show how complex solution with Web Application project can be build and files (result of publish operation) copied to drop location.
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns=http://schemas.microsoft.com/developer/msbuild/2003
ToolsVersion="3.5">
<PropertyGroup>
<OutputFiles>.\OutputFiles\</OutputFiles>
<ReleseFolder>D:\WcfFileTransfer\Release\</ReleseFolder>
<PrecompiledWeb>$(OutputFiles)_PublishedWebsites\WebHostApp\</PrecompiledWeb>
</PropertyGroup>
<Target Name="Clean">
<Exec Command="MSBuild.exe WcfFileTransfer.sln /t:Clean" />
</Target>
<Target Name="Build">
<Exec Command="MSBuild.exe WcfFileTransfer.sln /t:Rebuild /p:Configuration=Release
/p:OutDir=..\$(OutputFiles)" ContinueOnError="False" />
<ItemGroup>
<!--include needed files-->
<WebFiles Include="$(PrecompiledWeb)**\*.*"
Exclude="$(PrecompiledWeb)**\developer.config;$(PrecompiledWeb)**\HOWTO*.*"/>
</ItemGroup>
<!--show message-->
<Message Text="Copying to Deployment Dir:@(WebFiles) to $(ReleseFolder) :" />
<!--perform recursive copy-->
<Copy
SourceFiles="@(WebFiles)"
DestinationFiles="@(WebFiles->'$(ReleseFolder)\%(RecursiveDir)\%(Filename)%(Extension)')" />
</Target>
</Project>
This script is executed from Visual Studio Command Prompt like this
MSBuild build.proj
For more information about MSBuild you can take a look at MSDN reference page or Channel9 Wiki:
Or the MSBuild: By Example tutorial:
- Introducing Well-Known Metadata
- Formatting Your Output
- Editing MSBuild Files with IntelliSense
- Integrating MSBuild into Visual Studio
- Introducing Custom Metadata
- Understanding the Difference Between @ and %
- Using Environment Variables in Your Project
- Reusing MSBuild Project Elements
- Dealing with MSBuild Errors
I hope this is good as a start.