Inrtroduction


Before we start work with MSBuild we need to know, what is MSBuild? When we need to use MSBuild? What MSBuild Does? How can I start with MSBuild?

Introduction

               MSBuild is Engine looks for XML file to execute. The XML file (Any file extension like proj, vcproj, sln, xml, msbuild ). It’s not compulsory to have (.vcproj or. proj file) visual studio file format. MSBuild is provided by Microsoft Visual studio but there is no dependency with visual studio to execute it. Visual studio uses MSBuild to build project, without Visual studio we can use MSBuild by using command or TFS. MSBuild load and build managed projects. From MSBuild 4.0 Visual C++ is also supported now.



When we need to use MSBuild?

               Initially when build is done by visual studio it uses MSBuild but incase Continues integration is happen in projects and build project through the visual studio is costly and time expensive. Instead of using Visual studio build process is better to use MSBuild to automate build.

What MSBuild Does?

               MSBuild takes XML file to Execute build process. XML contains Targets, Properties, Items and Tasks which decide build execution and output. XML file which contains <Project> node with list of <Target> nodes. MSBuild executions start with <Project> node. Visual Studio projects have XML files like ( vcproj, proj ) which is used by MSBuild.

How can I start with MSBuild?

1.Start with Simple program says Hello
File: BuildAutomateDemo1.proj
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="BuildAutomateStart">
    <Message Text="Hello"/> 
  </Target>
</Project>



2.MSbuild with multiple targets using command line


<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="BuildAutomateStart">
    <Message Text="Hello"/> 
  </Target>
  <Target Name="BuildAutomateEnd">
    <Message Text="Bye Bye !"/> 
  </Target>
</Project>


Alternate way, using DependsOnTargets

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="BuildAutomateEnd">
  <Target Name="BuildAutomateStart" >
    <Message Text="Hello"/> 
  </Target>
  <Target Name="BuildAutomateEnd" DependsOnTargets="BuildAutomateStart">
    <Message Text="Bye Bye !"/> 
  </Target>
</Project>









No comments:

Post a Comment