public BuilderOptions(Logger logger) { Logger = logger; Plugins = new PluginResolver(logger); BuilderMode = Builder.Mode.Build; }
public bool Compile(PluginResolver pluginResolver) { // Prepare compilation of C# makefile var assemblyLocations = new List<string> { "mscorlib.dll", "System.dll", "System.Core.dll", typeof(Command).Assembly.Location, // Add BuildTool.Shared by default }; ParseParameters(); foreach (string additionalPluginDirectories in parameters.GetRange("PluginDirectory")) { pluginResolver.AddPluginFolder(Path.Combine(Path.GetDirectoryName(ScriptPath) ?? "", additionalPluginDirectories)); } foreach (string assemblyLocation in parameters.GetRange("Assembly")) { // 1. Try to find relative to source location first var testAssemblyLocation = Path.Combine(Path.GetDirectoryName(ScriptPath) ?? "", assemblyLocation); if (!File.Exists(testAssemblyLocation)) { // 2. Try to find in plugin folders testAssemblyLocation = pluginResolver.FindAssembly(Path.GetFileName(assemblyLocation)); if (!File.Exists(testAssemblyLocation)) { // 3. Try to find in current assembly directory testAssemblyLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "", Path.GetFileName(assemblyLocation) ?? ""); if (!File.Exists(testAssemblyLocation)) parsingErrors.Add(string.Format("Could not find assembly {0}", assemblyLocation)); } } assemblyLocations.Add(testAssemblyLocation); } // SourceBaseDirectory - optional if (parameters.ContainsSingle("SourceBaseDirectory")) SourceBaseDirectory = parameters.GetSingle("SourceBaseDirectory"); else if (parameters.ContainsMultiple("BuildDirectory")) parsingErrors.Add("Source base directory defined multiple times."); else parsingWarnings.Add("Source base directory not defined."); // BuildDirectory - mandatory if (parameters.ContainsSingle("BuildDirectory")) BuildDirectory = parameters.GetSingle("BuildDirectory"); else if (parameters.ContainsMultiple("BuildDirectory")) parsingErrors.Add("Build directory defined multiple times."); else parsingErrors.Add("Build directory not defined."); // OutputDirectory - optional if (parameters.ContainsSingle("OutputDirectory")) OutputDirectory = parameters.GetSingle("OutputDirectory"); else if (parameters.ContainsMultiple("OutputDirectory")) parsingErrors.Add("Output directory defined multiple times."); else parsingWarnings.Add("Output directory not defined."); // MetadataDatabaseDirectory - optional if (parameters.ContainsSingle("MetadataDatabaseDirectory")) MetadataDatabaseDirectory = parameters.GetSingle("MetadataDatabaseDirectory"); else if (parameters.ContainsMultiple("MetadataDatabaseDirectory")) parsingErrors.Add("Metadata database directory defined multiple times."); else parsingWarnings.Add("Metadata database not defined."); var sourceFolderKeys = parameters.GetRange("SourceFolderKey").ToArray(); var sourceFolderValue = parameters.GetRange("SourceFolderValue").ToArray(); for (int i = 0; i < sourceFolderKeys.Length; ++i) { ((Dictionary<string, string>)SourceFolders).Add(sourceFolderKeys[i], sourceFolderValue[i]); } if (HasErrors) { return false; } // Compile C# makefile var csc = new CSharpCodeProvider(new Dictionary<string, string> { { "CompilerVersion", "v4.0" } }); var compileParams = new CompilerParameters(assemblyLocations.ToArray()) { GenerateInMemory = true, IncludeDebugInformation = true }; compilerResult = csc.CompileAssemblyFromFile(compileParams, ScriptPath); IsCompiled = !HasErrors; return IsCompiled; }
public BuilderOptions(Logger logger) { Logger = logger; Plugins = new PluginResolver(logger); BuilderMode = Builder.Mode.Build; }
public bool Compile(PluginResolver pluginResolver) { // Prepare compilation of C# makefile var assemblyLocations = new List <string> { "mscorlib.dll", "System.dll", "System.Core.dll", typeof(Command).Assembly.Location, // Add BuildTool.Shared by default }; ParseParameters(); foreach (string additionalPluginDirectories in parameters.GetRange("PluginDirectory")) { pluginResolver.AddPluginFolder(Path.Combine(Path.GetDirectoryName(ScriptPath) ?? "", additionalPluginDirectories)); } foreach (string assemblyLocation in parameters.GetRange("Assembly")) { // 1. Try to find relative to source location first var testAssemblyLocation = Path.Combine(Path.GetDirectoryName(ScriptPath) ?? "", assemblyLocation); if (!File.Exists(testAssemblyLocation)) { // 2. Try to find in plugin folders testAssemblyLocation = pluginResolver.FindAssembly(Path.GetFileName(assemblyLocation)); if (!File.Exists(testAssemblyLocation)) { // 3. Try to find in current assembly directory testAssemblyLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "", Path.GetFileName(assemblyLocation) ?? ""); if (!File.Exists(testAssemblyLocation)) { parsingErrors.Add(string.Format("Could not find assembly {0}", assemblyLocation)); } } } assemblyLocations.Add(testAssemblyLocation); } // SourceBaseDirectory - optional if (parameters.ContainsSingle("SourceBaseDirectory")) { SourceBaseDirectory = parameters.GetSingle("SourceBaseDirectory"); } else if (parameters.ContainsMultiple("BuildDirectory")) { parsingErrors.Add("Source base directory defined multiple times."); } else { parsingWarnings.Add("Source base directory not defined."); } // BuildDirectory - mandatory if (parameters.ContainsSingle("BuildDirectory")) { BuildDirectory = parameters.GetSingle("BuildDirectory"); } else if (parameters.ContainsMultiple("BuildDirectory")) { parsingErrors.Add("Build directory defined multiple times."); } else { parsingErrors.Add("Build directory not defined."); } // OutputDirectory - optional if (parameters.ContainsSingle("OutputDirectory")) { OutputDirectory = parameters.GetSingle("OutputDirectory"); } else if (parameters.ContainsMultiple("OutputDirectory")) { parsingErrors.Add("Output directory defined multiple times."); } else { parsingWarnings.Add("Output directory not defined."); } // MetadataDatabaseDirectory - optional if (parameters.ContainsSingle("MetadataDatabaseDirectory")) { MetadataDatabaseDirectory = parameters.GetSingle("MetadataDatabaseDirectory"); } else if (parameters.ContainsMultiple("MetadataDatabaseDirectory")) { parsingErrors.Add("Metadata database directory defined multiple times."); } else { parsingWarnings.Add("Metadata database not defined."); } var sourceFolderKeys = parameters.GetRange("SourceFolderKey").ToArray(); var sourceFolderValue = parameters.GetRange("SourceFolderValue").ToArray(); for (int i = 0; i < sourceFolderKeys.Length; ++i) { ((Dictionary <string, string>)SourceFolders).Add(sourceFolderKeys[i], sourceFolderValue[i]); } if (HasErrors) { return(false); } // Compile C# makefile var csc = new CSharpCodeProvider(new Dictionary <string, string> { { "CompilerVersion", "v4.0" } }); var compileParams = new CompilerParameters(assemblyLocations.ToArray()) { GenerateInMemory = true, IncludeDebugInformation = true }; compilerResult = csc.CompileAssemblyFromFile(compileParams, ScriptPath); IsCompiled = !HasErrors; return(IsCompiled); }