public static void Generate(string sourcePath, string outputPath, ConsoleLogger logger) { if (!Directory.Exists(sourcePath)) { throw new DirectoryNotFoundException($"The path `{sourcePath}` does not exist. Unable to generate Azure Functions extensions metadata file."); } var extensionReferences = new List <ExtensionReference>(); var targetAssemblies = Directory.EnumerateFiles(sourcePath, "*.dll") .Where(f => !AssemblyShouldBeSkipped(Path.GetFileName(f))) .ToArray(); logger.LogMessage($"Found {targetAssemblies.Length} assemblies to evaluate in '{sourcePath}':"); foreach (var path in targetAssemblies) { using (logger.Indent()) { logger.LogMessage($"{Path.GetFileName(path)}"); using (logger.Indent()) { try { Assembly assembly = Assembly.LoadFrom(path); var currExtensionReferences = GenerateExtensionReferences(assembly); extensionReferences.AddRange(currExtensionReferences); foreach (var foundRef in currExtensionReferences) { logger.LogMessage($"Found extension: {foundRef.TypeName}"); } } catch (Exception ex) when(ex is FileNotFoundException || ex is BadImageFormatException) { // Don't log this as an error. This will almost always happen due to some publishing artifacts (i.e. Razor) existing in the // functions bin folder without all of their dependencies present, or native package artifacts being copied to the bin folder // These will almost never have Functions extensions, so we don't want to write out errors every time there is a build. // This message can be seen with detailed logging enabled. logger.LogMessage($"Could not evaluate '{Path.GetFileName(path)}' for extension metadata. If this assembly contains a Functions extension, ensure that all dependent assemblies exist in '{sourcePath}'. If this assembly does not contain any Functions extensions, this message can be ignored. Exception message: {ex.Message}"); } catch (Exception ex) { logger.LogError($"Could not evaluate '{Path.GetFileName(path)}' for extension metadata. Exception message: {ex.Message}"); } } } } string json = GenerateExtensionsJson(extensionReferences); File.WriteAllText(outputPath, json); logger.LogMessage($"'{outputPath}' successfully written."); }
public static void Generate(string sourcePath, string outputPath, ConsoleLogger logger) { if (!Directory.Exists(sourcePath)) { throw new DirectoryNotFoundException($"The path `{sourcePath}` does not exist. Unable to generate Azure Functions extensions metadata file."); } var extensionReferences = new List <ExtensionReference>(); var targetAssemblies = Directory.EnumerateFiles(sourcePath, "*.dll") .Where(f => !AssemblyShouldBeSkipped(Path.GetFileName(f))) .ToArray(); logger.LogMessage($"Found {targetAssemblies.Length} assemblies to evaluate in '{sourcePath}':"); foreach (var path in targetAssemblies) { using (logger.Indent()) { logger.LogMessage($"{Path.GetFileName(path)}"); using (logger.Indent()) { try { var currExtensionReferences = GenerateExtensionReferences(path, logger); extensionReferences.AddRange(currExtensionReferences); foreach (var foundRef in currExtensionReferences) { logger.LogMessage($"Found extension: {foundRef.TypeName}"); } } catch (BadImageFormatException) { // No need to log here as we can ignore these as extensions. } catch (Exception ex) { logger.LogError($"Could not evaluate '{Path.GetFileName(path)}' for extension metadata. Exception message: {ex}"); } } } } string json = GenerateExtensionsJson(extensionReferences); File.WriteAllText(outputPath, json); logger.LogMessage($"'{outputPath}' successfully written."); }