コード例 #1
0
        public static string ExtractSourceFileList(ProjectConfiguration configuration, string sourceDirectory) {
            var fileList = new List<string>();

            foreach(var sourceFile in configuration.SourceFiles) {
                fileList.Add(sourceDirectory + sourceFile);
            }

            return string.Join(" ", fileList);
        }
コード例 #2
0
        public static string ExtractPackageList(ProjectConfiguration configuration) {

            if(configuration.PackageList == null || configuration.PackageList.Count == 0) {
                return string.Empty;
            }

            var packageList = string.Join(",", configuration.PackageList);

            return string.Format("-pkg:{0}", packageList);
        }
コード例 #3
0
        public static string ExtractLibraryPath(ProjectConfiguration configuration) {

            if(configuration.LibraryPath == null || configuration.LibraryPath.Count == 0) {
                return string.Empty;
            }

            var libraryPath = string.Join(",", configuration.LibraryPath);

            return string.Format("-lib:{0}", libraryPath);
        }
コード例 #4
0
        public static string ExtractBuildTarget(ProjectConfiguration configuration) {

            switch(configuration.BuildTarget) {
                case "exe":
                case "library":
                case "module":
                case "winexe":
                    return string.Format("-target:{0}", configuration.BuildTarget);
                default:
                    return "-target:exe";
            }

        }
コード例 #5
0
        public static string ExtractReferences(ProjectConfiguration configuration) {

            if(configuration.References == null || configuration.References.Count == 0) {
                return string.Empty;
            }

            var referenceList = new List<string>();
            foreach(var reference in configuration.References) {
                referenceList.Add(reference.Name);
            }

            var referenceString = string.Join(",", referenceList);

            return string.Format("-r:{0}", referenceString);
        }
コード例 #6
0
        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;
        }
コード例 #7
0
        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);
            }

        }
コード例 #8
0
 public static Command CreateCommand(ProjectConfiguration project) {
     return CommandBuilder.BuildCommand(project);
 }
コード例 #9
0
        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);

            }
        }
コード例 #10
0
        public static string SetWarningLevel(ProjectConfiguration configuration) {

            if(string.IsNullOrEmpty(configuration.WarningLevel)) {
                return string.Empty;
            }

            int warningLevel;
            bool isNumeric = int.TryParse(configuration.WarningLevel, out warningLevel);

            if(!isNumeric) {
                return string.Empty;
            }

            if(warningLevel >=0 && warningLevel <= 4) {
                return string.Format("-warn:{0}", warningLevel);
            }

            Console.WriteLine("Warning: Invalid value for warning level ({0}), using the default value for the compiler.",
                configuration.WarningLevel);
            return string.Empty;
        }
コード例 #11
0
        public static string TreatWarningsAsErrors(ProjectConfiguration configuration) {

            if(string.IsNullOrEmpty(configuration.WarningsAsErrors)) {
                return string.Empty;
            }

            bool warningsAsErrors;
            bool isBoolean = bool.TryParse(configuration.WarningsAsErrors, out warningsAsErrors);

            if(!isBoolean) {
                Console.WriteLine("Warning: Invalid value for WarningsAsErrors, using the default value for the compiler.");
                return string.Empty;
            }

            return warningsAsErrors ? "-warnaserror+" : "-warnaserror-";
        }