Geeks With Blogs

News My Blog has been MOVED to
Michael Freidgeim's OLD Blog My Blog has been MOVED to

I wanted to create batch to backup source files from my Projects folder, but also exclude some folders that I do not use.

I was amased how quickly I was able to do it using MSBuild project without any previous experience with the tool.

The purpose of the project is to copy files with specified extensions from specified folder and all subfolders, excluding some subfolders

The Destination folder name is generated based on current time.

The batch file to start utility:

call "C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat" x86
msbuild.exe /v:m BackupSrc.xml

The BackupSrc.xml project file is the following:

<Project xmlns="">

  <PropertyGroup >








               Exclude="$(ExcludeFolders)" />



               Exclude="$(ExcludeFolders)" />


    <UsingTask TaskName="FolderName"

                  AssemblyFile="C:\Projects\Utilities\MSBuild\CustomTasks\bin\Debug\CustomTasks.dll" />

    <Target Name="CopyFiles">


        <Output TaskParameter="FolderNameAsNow" PropertyName="FolderDate" />










Note that XML is slightly corrupted by HTML editor that Iam using for blogging. 



I've also created a CusomTasks.DLL to create a FolderName by formatting  the current date.



using System;

using System.Collections.Generic;

using System.Text;


namespace CustomTasks


    using Microsoft.Build.Framework;

    using Microsoft.Build.Utilities;


        public class FolderName : Task


            public override bool Execute()


                myFolderNameAsNow = GetDateTimeFolder();

                return true;



            private string myFolderNameAsNow;

            [Output] // attribute is important

            public string FolderNameAsNow


                get { return myFolderNameAsNow; }

                set { myFolderNameAsNow = value; }


            private static string GetDateTimeFolder()


                return "F_" + DateTime.Now.ToString("yyMMdd_HHmm");





MSBuild Related links: MSBuild Community Tasks Project ,

Sdc.Tasks on gotdotnet,

subtree copy task,

SetMetadata sample on Visual Studio MSBuild forums, 

Microsoft Build Sidekick


Less related to the article links about MSBuild:
How to call the same target multiple times at different build stages?


Alternatively see free


ROBOCOPY.exe (XP Resource Kit/Standard Vista command)

JaBack - Automated Data Backup Software, File Backup Software 
Posted on Friday, February 17, 2006 1:42 PM | Back to top

Comments on this post: Backup source files using MSBuild project.

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Michael Freidgeim | Powered by: