Wiki
Version 4 (modified by Charles, 13 years ago)

--

MsxBuild

Microsoft .NET comes with a build tool called "msbuild" which Novell Mono calls "xbuild". This document will use the name "msbuild" henceforth, but will be referring to both of them as they take the same input files and produce the same results.

Example

<Project DefaultTargets="Build"
    xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <PropertyGroup>
        <ProjectName>Company.Project</ProjectName>
        <OutputDir>build</OutputDir>
        <BuildPartsDir>parts</BuildPartsDir>
    </PropertyGroup>

    <ItemGroup>

        <CobraFlags Include="-d"/>
        <CobraFlags Include="-correct-source"/>

        <CobraFiles Include="source\A.cobra"/>
        <CobraFiles Include="source\B.cobra"/>
        <CobraFiles Include="source\C.cobra"/>

        <References Include="System"/>
        <References Include="System.Web"/>

    </ItemGroup>

    <Target Name="Clean">
        <RemoveDir Directories="$(OutputDir)"/>
    </Target>

    <Target Name="Build">
        <CallTarget Targets="Reset"/>
        <Exec Command="cobra -c -t:lib @(CobraFlags, ' ') -out:$(OutputDir)/$(ProjectName).dll @(References -> '-ref:%(Identity)', ' ') @(CobraFiles, ' ')"/>
    </Target>

    <Target Name="Test">
        <CallTarget Targets="Reset"/>
        <Exec Command="cobra -test @(CobraFlags, ' ') -out:$(OutputDir)/$(ProjectName).dll @(References -> '-ref:%(Identity)', ' ') @(CobraFiles, ' ')"/>
    </Target>

    <Target Name="Reset">
        <CallTarget Targets="Clean"/>
        <MakeDir Condition="!Exists('$(OutputDir)')" Directories="$(OutputDir)"/>
    </Target>

</Project>

Then at the command line, a simple "msbuild" (or "xbuild" on Mono) will pick the lone *.proj file and build its default target:

msbuild

If there is more than one .proj file, you can pass it on the command line:

msbuild foo.proj

To build a specific target:

msbuild /t:test

Targets are case insensitive.

Notes

You don't need to use a build tool for single files or very small projects.

You can embed library references in your Cobra source code with the RefDirective? (@ref) and thereby skip passing them on the command line.

Alternatives to msbuild/xbuild include Nant, Make and scripts (such as bash or .bat).

See Also