Using msbuild (RTM) as the build tool for an automated build without using built-in targets

I decided that, because I am now building all my personal projects in .Net 2.0, I should try and use msbuild as an automated build tool instead of NAnt.
 
Requirements: Installation of .Net Framework 2.0 (RTM) SDK
 
For this example, my folder structure is as follows:
 
   Root
             build.bat
             Application.Targets
             Build
             Source
                         Application 
                                            First
                                                     *.cs
                                            Dependent
                                                                 *.cs
 
I created a batch file to automate the build process called build.bat and placed it in the root directory.
 
build.bat :
@echo off
%WINDIR%Microsoft.NETFrameworkv2.0.50727msbuild.exe Application.Targets

 

The dependent application has a reference to the First library.
The result of the build is to delete the RootBuild directory and all its contents (cleaning the build directory), recreate it, and then build the applications in the build directory.
 
Application.Targets:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <BuildDirectory>Build</BuildDirectory>
        <SourceDirectory>Source</SourceDirectory>
        <SourceFirstDllDirectory>First</SourceFirstDllDirectory>
        <SourceDependentApplicationDirectory>Dependent</SourceDependentApplicationDirectory>
    </PropertyGroup>
    <Target Name="BuildAll" DependsOnTargets="CleanBuildDirectory;CreateBuildDirectory;BuildFirstDll;BuildDependentApplication" />
    <Target Name="CleanBuildDirectory">
        <Exec Command="rd /q /s $(BuildDirectory)" />
    </Target>
    <Target Name="CreateBuildDirectory">
     <MakeDir Directories="$(BuildDirectory)" />
    </Target>
    <ItemGroup>
     <First Include="$(SourceDirectory)$(SourceFirstDllDirectory)***.cs" />
    </ItemGroup>
    <Target Name="BuildFirstDll">
     <Csc Sources="@(First)" TargetType="library" OutputAssembly="$(BuildDirectory)First.dll" />
    </Target>
    <ItemGroup>
     <DependentApplication Include="$(SourceDirectory)$(SourceDependentApplicationDirectory)***.cs" />
    </ItemGroup>
    <Target Name="BuildDependentApplication" DependsOnTargets="BuildFirstDll">
     <Csc Sources="@(DependentApplication)" TargetType="library"
      References="$(BuildDirectory)First.dll"
     OutputAssembly="$(BuildDirectory)Dependent.dll" />
    </Target>
</Project>
 
 

Leave a comment