public static Command BuildCommand(ProjectConfiguration configuration) {
            var command = new Command();
            command.SourceDirectory = string.IsNullOrEmpty(configuration.SourceDirectory)
                ? command.SourceDirectory : configuration.SourceDirectory;
            command.DestinationDirectory = string.IsNullOrEmpty(configuration.DestinationDirectory)
                ? command.DestinationDirectory : configuration.DestinationDirectory;
            command.OutputFilename = string.IsNullOrEmpty(configuration.OutputFilename)
                ? ""
                : string.Format("-out:{0}{1}", command.DestinationDirectory, configuration.OutputFilename);
            command.SourceFiles = ExtractSourceFileList(configuration, command.SourceDirectory);
            command.BuildTarget = ExtractBuildTarget(configuration);
            command.References = ExtractReferences(configuration);
            command.LibraryPath = ExtractLibraryPath(configuration);
            command.PackageList = ExtractPackageList(configuration);
            command.WarningLevel = SetWarningLevel(configuration);
            command.WarningsAsErrors = TreatWarningsAsErrors(configuration);

            return command;
        }
        public static void EnsureDestinationDirectoryExists(Command command) {

            if(string.IsNullOrEmpty(command.DestinationDirectory)) {
                command.DestinationDirectory = "./build";
            }

            if(Directory.Exists(command.DestinationDirectory)) {
                // Directory already exists.
                return;
            }

            try {
                Directory.CreateDirectory(command.DestinationDirectory);
            }
            catch(Exception) {
                Console.WriteLine("Unable to create destination directory.");
                throw;
            }

        }
        public static BuildStatistics BuildProject(Command command) {
            Console.WriteLine(command.GenerateArgumentList());
            var processInfo = new ProcessStartInfo(command.CommandName);
            processInfo.Arguments = command.GenerateArgumentList();
            processInfo.UseShellExecute = true;
            processInfo.WorkingDirectory = Directory.GetCurrentDirectory();
            Console.WriteLine(Directory.GetCurrentDirectory());
            Console.WriteLine("Build starting...");
            var process = new Process();
            process.EnableRaisingEvents = true;
            process.StartInfo = processInfo;
            var stopWatch = Stopwatch.StartNew();
            process.Start();
            process.WaitForExit();
            stopWatch.Stop();

            return new BuildStatistics {
                ExitCode = process.ExitCode,
                ElapsedTime = stopWatch.Elapsed
            };
        }
        public static void CopyReferences(ProjectConfiguration project, Command command) {

            if(project.References == null || project.References.Count == 0) {
                return;
            }

            var destinationDirectory = command.DestinationDirectory;

            foreach(var reference in project.References) {

                if(string.IsNullOrEmpty(reference.Path)) {
                    continue;
                }

                var path = reference.Path;
                var referenceName = reference.Name;
                var fileExtension = ".dll";

                File.Copy(string.Format("{0}{1}{2}", path, referenceName, fileExtension),
                          string.Format("{0}{1}{2}", destinationDirectory, referenceName, fileExtension),
                          true);
            }

        }
        public static void CopyResources(ProjectConfiguration project, Command command) {

            if(project.Resources == null || project.Resources.Count == 0) {
                return;
            }

            foreach(var resource in project.Resources) {
                var sourceDirectory = Path.GetDirectoryName(resource.Source);
                var destinationDirectory = Path.GetDirectoryName(resource.Destination);
                Console.WriteLine("Source Directory: {0}", sourceDirectory);
                Console.WriteLine("Destination Directory: {0}", destinationDirectory);

                if(!Directory.Exists(string.Format("{0}{1}", command.DestinationDirectory, destinationDirectory))) {

                    try {
                        Directory.CreateDirectory(string.Format("{0}{1}", command.DestinationDirectory, destinationDirectory));
                    }
                    catch(Exception) {
                        Console.WriteLine("Unable to create destination directory.");
                        throw;
                    }

                }

                File.Copy(string.Format("{0}{1}", command.SourceDirectory, resource.Source),
                          string.Format("{0}{1}", command.DestinationDirectory, resource.Destination),
                          true);

            }
        }