Microsoft MSBuild Tutorial

Find Tips and tricks on how to better use the Zeus IDE. Feel free to post your own tips but please do not post bug reports, feature requests or questions here.
Post Reply
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Microsoft MSBuild Tutorial

Post 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
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            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()
        {
            InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        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="http://schemas.microsoft.com/developer/msbuild/2003" >

    <PropertyGroup>
        <!-- Set the application name as a property -->
        <appname>MyProject</appname>

        <!-- Set the output folder as a property -->
        <builtdir>Output</builtdir>
    </PropertyGroup>

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

    <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" />
        </CSC>

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

    <Target Name = "Clean">
        <RemoveDir Directories="$(builtdir)" />
    </Target>
</Project>
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
Post Reply