/// <summary> /// Loads all Sharpmake extensions in a directory. /// </summary> /// <param name="directory">The path to the directory to scan for assemblies.</param> /// <returns>A <see cref="IEnumerable{T}"/> that contains the loaded <see cref="Assembly"/>.</returns> public IEnumerable <Assembly> LoadExtensionsInDirectory(string directory) { if (directory == null) { throw new ArgumentNullException(nameof(directory)); } if (!Directory.Exists(directory)) { throw new DirectoryNotFoundException($"Directory {directory} does not exist."); } CreateRemoteExtensionCheckerIfNeeded(); var assemblies = new List <Assembly>(); IEnumerable <string> dlls = Directory.EnumerateFiles(directory, "*.dll", SearchOption.TopDirectoryOnly); foreach (var dll in dlls) { if (IsExtension(dll)) { try { assemblies.Add(LoadExtension(dll, true)); } catch (Exception ex) { Util.LogWrite("Failure to load assembly {0}. This may cause runtime errors.\nDetails: {1}", Path.GetFileName(dll), ex.Message); } } } return(assemblies); }
public override void ParseParameter(string[] parameters, FileInfo sourceFilePath, int lineNumber, IAssemblerContext context) { string reference = parameters[0]; if (Util.IsPathWithWildcards(reference)) { string referenceAbsolutePath = Path.IsPathRooted(reference) ? reference : null; referenceAbsolutePath = referenceAbsolutePath ?? Path.Combine(sourceFilePath.DirectoryName, reference); context.AddReferences(Util.DirectoryGetFilesWithWildcards(referenceAbsolutePath)); } else { bool foundReference = false; foundReference = Assembler.DefaultReferences.Any( defaultReference => FileSystemStringComparer.StaticCompare(defaultReference, reference) == 0 ); if (!foundReference) { foreach (string candidateReferenceLocation in EnumerateReferencePathCandidates(sourceFilePath, reference)) { if (Util.FileExists(candidateReferenceLocation)) { context.AddReference(candidateReferenceLocation); foundReference = true; break; } } } else if (Builder.Instance.Diagnostics) { Util.LogWrite("{0}({1}): Warning: Reference '{2}' is redundant and can be removed since it is in the default reference list.", sourceFilePath.FullName, lineNumber, reference); } if (!foundReference) { throw new Error( "\t{0}({1}): error: Sharpmake.Reference file not found: {2}{3}Those paths were evaluated as candidates:{3} - {4}", sourceFilePath.FullName, lineNumber, reference, Environment.NewLine, string.Join(Environment.NewLine + " - ", EnumerateReferencePathCandidates(sourceFilePath, reference)) ); } } }