public BuildTarget(int lineNumber, PropertyGroup targetProps, ItemGroup targetItems) { LineNumber = lineNumber; Properties = targetProps; Items = targetItems; Name = targetProps.GetRequiredValue("TargetName"); InputFiles = targetItems.GetRequiredValue("TargetInputs"); OutputFiles = targetItems.GetRequiredValue("TargetOutputs"); Func <IList <ParsedPath>, IEnumerable <string> > extractAndSortExtensions = (files) => { return(files.Select <ParsedPath, string>(f => f.Extension).Distinct <string>().OrderBy(s => s, StringComparer.CurrentCultureIgnoreCase)); }; InputExtensions = extractAndSortExtensions(InputFiles); OutputExtensions = extractAndSortExtensions(OutputFiles); }
private List <CompilerClass> LoadCompilerClasses(ItemGroup itemGroup, PropertyGroup propGroup) { List <CompilerClass> compilerClasses = new List <CompilerClass>(); IList <ParsedPath> paths = itemGroup.GetRequiredValue("CompilerAssembly"); foreach (var path in paths) { Assembly assembly = null; try { // We use Assembly.Load so that the test assembly and subsequently loaded // assemblies end up in the correct load context. If the assembly cannot be // found it will raise a AssemblyResolve event where we will search for the // assembly. assembly = Assembly.LoadFrom(path); } catch (Exception e) { throw new ApplicationException(String.Format("Unable to load content compiler assembly file '{0}'. {1}", path, e.ToString()), e); } Type[] types; // We won't get dependency errors until we actually try to reflect on all the types in the assembly try { types = assembly.GetTypes(); } catch (ReflectionTypeLoadException e) { string message = String.Format("Unable to reflect on assembly '{0}'", path); // There is one entry in the exceptions array for each null in the types array, // and they correspond positionally. foreach (Exception ex in e.LoaderExceptions) { message += Environment.NewLine + " " + ex.Message; } // Not being able to reflect on classes in the test assembly is a critical error throw new ApplicationException(message, e); } // Go through all the types in the test assembly and find all the // compiler classes, those that inherit from IContentCompiler. foreach (var type in types) { Type interfaceType = type.GetInterface(typeof(IContentCompiler).ToString()); if (interfaceType != null) { CompilerClass compilerClass = new CompilerClass(assembly, type); compilerClasses.Add(compilerClass); } } } return(compilerClasses); }