Page 1 of 1

Microsoft MSBuild Tutorial

Posted: Wed Apr 15, 2009 4:28 am
by jussij
Here is a simple tutorial on how to use a Zeus workspace and the Microsoft MSBuild tool to manage a two file C# project.

Step 1: Create this MyProgram.cs file:

Code: Select all

using System;
using System.Windows.Forms;

namespace SampleApplication
    static class Program
        static void Main()
            Application.Run(new MyForm());
Step 2: Create this MyForm.cs file:

Code: Select all

using System;
using System.Windows.Forms;

namespace SampleApplication
    public class MyForm : Form
        private System.ComponentModel.IContainer components = null;

        public MyForm()

        protected override void Dispose(bool disposing)
            if (disposing && (components != null))

        private void InitializeComponent()
            this.components = new System.ComponentModel.Container();
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Text = "MyForm";
Step 3: Create this MyProject.proj file:

Code: Select all

<Project DefaultTargets = "Build"
    xmlns="" >

        <!-- Set the application name as a property -->

        <!-- Set the output folder as a property -->

        <!-- Specify the inputs by type and file name -->
        <CSFile Include = "MyForm.cs"/>
        <CSFile Include = "MyProgram.cs"/>   

    <Target Name = "Build">
        <!-- Check whether an output folder exists and create
        one if necessary -->
        <MakeDir Directories = "$(builtdir)"
            Condition = "!Exists('$(builtdir)')" />

        <!-- Run the Visual C# compiler -->
        <CSC Sources = "@(CSFile)"
            DebugType = "full"
            OutputAssembly = "$(BuiltDir)\$(appname).exe">
            <Output TaskParameter = "OutputAssembly"
                ItemName = "EXEFile" />

        <!-- Log the file name of the output file -->
        <Message Text="The output file is @(EXEFile)"/>

    <Target Name = "Clean">
        <RemoveDir Directories="$(builtdir)" />
Step 4: Create a Zeus workspace and add these three files to the workspace.

Step 5: Use the Workspace, Options menu and in the Project panel define the following command lines:
  • Make Command Line: msbuild.exe MyProject.proj
  • Rebuild All Command Line: msbuild.exe MyProject.proj /t:Clean;Build
  • Clean Command Line: msbuild.exe MyProject.proj /t:Clean
Step 6: Use the Workspace, Project menus to run these different builds.

For example running the Project Rebuild menu will create the Output\MyProject.exe file with the following output:

Code: Select all

     Zeus for Windows Programmers Editor - Version 3.96t-beta6
     Copyright (c) Xidicone P/L 1993-2009.  All rights reserved.

--------------------Configuration: MyProject - Debug--------------------
Microsoft (R) Build Engine Version 2.0.50727.1433
[Microsoft .NET Framework, Version 2.0.50727.1433]
Copyright (C) Microsoft Corporation 2005. All rights reserved.

Build started 15/04/2009 14:26:21.
Project "C:\MyProject\MyProject.proj" (Clean;Build target(s)):

Target Clean:
    Directory "Output" doesn't exist. Skipping.
Target Build:
    Creating directory "Output".
    d:\WINNT\Microsoft.NET\Framework\v2.0.50727\Csc.exe /out:Output\MyProject.exe MyForm.cs MyProgram.cs
    The output file is Output\MyProject.exe

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:05.65
More information:
MSBuild Reference
MSBuild Task Reference

Cheers Jussi