MSBuild Introduction

As a follow up to my previous post on cruise control.

Let's look at what msbuild can do.

Many developers did not reliaze that when they make a project or solution, visual studio create an msbuild script . that is on your ProjectName.Csproj for c#project,as for web it just contain the path of the build on sln, this is what the web deployment project comes in creating additional msbuild for web

So when you click on Build ,Rebuild or Clean, Visual studio actually execute the script using MSbuild.

You can see the csproj using notepad or You might wondering How the hell i can see that xml on my Vs IDE?. the answer is right click on your project ->Click Unload Project -> Rightclick on your disable project -> Edit MyprojectName.CSproj.

Msbuild work on Targets.

Msbuild possessed property , and each target can have items.

You can do Import Targets. Using tag is used for Using your own DLL.

Msbuild can be customized  as you wish

Let's Take an Example: I've got a pop3 projects that change the app.config during SIT,UAT and i want to email my others developer everytime i build

Now  how can i automated that every time i build the project?

By Default Visual studio already give you the place , now lets edit our project.

  1.  Add an SIT and UAT Configuration in your Configuration Manager

ImageHost.org

add the extension pack for Msbuild on your csproj ,i'm using the MSBuild Extension Pack , there is another option MSBuild Community extension.

 <PropertyGroup>

<TPath>C:\Program Files\MSBuild\ExtensionPack\MSBuild.ExtensionPack.tasks</TPath>
<TPath Condition="Exists('C:\Program Files\MSBuild\ExtensionPack\Common\MSBuild.ExtensionPack.tasks')">C:\Program Files\MSBuild\ExtensionPack\Common\MSBuild.ExtensionPack.tasks</TPath>   

... 

   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <Import Project="$(TPath)" />

 ...

 <Target Name="AfterBuild">
    <Message Text="Sending Email To Developers and QA" />
    <ItemGroup>
      <Attachment Include="C:\demo.txt" />
      <Recipient Include="penting@cipto.com" />
      <Recipient Include="iqbal@cipto.com" />
    </ItemGroup>
    <MSBuild.ExtensionPack.Communication.Email Attachments="@(Attachment)" TaskAction="Send" Subject="Pop3 is Build Version 1.0.0.1" SmtpServer="127.0.0.1" MailFrom="ciptoaja@cipto.com" MailTo="@(Recipient)" Body="HUii" />
    <Copy Condition="$(Configuration)=='UAT'" SourceFiles=".\uatconfig\Pop3Downloader.exe.config" DestinationFiles="$(OutputPath)Pop3Downloader.exe.config" />
    <Copy Condition="$(Configuration)=='SIT'" SourceFiles=".\sitconfig\Pop3Downloader.exe.config" DestinationFiles="$(OutputPath)Pop3Downloader.exe.config" />

  </Target>


 There you go. Now every time you build Copy the config and email other developer or qa

 Now you might wondering VS always create your first schema target="Build" etc comes from? i can't find it anywhere on my projects

well actually it imports them

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> and also

MSBuild ships with several useful tasks. For a complete list, see the Microsoft.Common.tasks file located in the %WinDir%\Microsoft.NET\Framework\v2.0.50727 directory

 22/10/2008 , You can add an external tool for accessing msbuild.exe from your ide.

click tools->External tools-> Fill TItle with MSBUild -> Fill command with C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe -> Fill arguments and initial directory

check the use output window, and prompt for arguments option.

 

ImageHost.org
Share this post: | | | |
Published Monday, October 20, 2008 10:10 AM by cipto
Filed under:

Comments

# re: MSBuild Introduction

Monday, October 20, 2008 2:16 PM by agusto xaverius

Mungkin ini jg bisa jadi satu opsi,baru download sich dan belum gw coba tapinya.

www.eworldui.net/unleashit

# re: MSBuild Introduction

Tuesday, October 21, 2008 9:13 AM by cipto

i've found a complete and better one.

Visual Build Professional.

complete cover of those tedious routine of deploying

# re: MSBuild Introduction

Thursday, October 23, 2008 9:21 AM by tedsfn

Gue biasa menggunakan Nant, dengan menggunakan cruisecontrol.net bisa buat autobuild/daily build. Tau bedanya gak dengan Msbuild? wich one is better?

# re: MSBuild Introduction

Thursday, October 23, 2008 10:29 AM by cipto

geekswithblogs.net/.../msbuild-or-nant.aspx.

i haven't use nant too much. but actually almost the same,since 2.0 microsoft use the msbuild.

and more enhance in .net 3.5