Prevent built in extensions from being declared in extensions.json
MODIFY
tools/ExtensionsMetadataGenerator/src/ExtensionsMetadataGenerator.Console/ExtensionsMetadataGenerator.cs
tools/ExtensionsMetadataGenerator/src/ExtensionsMetadataGenerator.Console/ExtensionsMetadataGenerator.cs
@@ -17,6 +17,9 @@ public class ExtensionsMetadataGenerator
{
private const string WebJobsStartupAttributeType = "Microsoft.Azure.WebJobs.Hosting.WebJobsStartupAttribute";
+ // These assemblies are always loaded by the functions runtime and should not be listed in extensions.json
+ private static readonly string[] ExcludedAssemblies = new[] { "Microsoft.Azure.WebJobs.Extensions.dll", "Microsoft.Azure.WebJobs.Extensions.Http.dll" };
+
public static void Generate(string sourcePath, string outputPath, Action<string> logger)
{
if (!Directory.Exists(sourcePath))
@@ -27,7 +30,7 @@ public static void Generate(string sourcePath, string outputPath, Action<string>
var extensionReferences = new List<ExtensionReference>();
var targetAssemblies = Directory.EnumerateFiles(sourcePath, "*.dll")
- .Where(f => !Path.GetFileName(f).StartsWith("System", StringComparison.OrdinalIgnoreCase));
+ .Where(f => !AssemblyShouldBeSkipped(Path.GetFileName(f)));
foreach (var path in targetAssemblies)
{
@@ -47,6 +50,8 @@ public static void Generate(string sourcePath, string outputPath, Action<string>
File.WriteAllText(outputPath, json);
}
+ public static bool AssemblyShouldBeSkipped(string fileName) => fileName.StartsWith("System", StringComparison.OrdinalIgnoreCase) || ExcludedAssemblies.Contains(fileName, StringComparer.OrdinalIgnoreCase);
+
public static string GenerateExtensionsJson(IEnumerable<ExtensionReference> extensionReferences)
{
var referenceObjects = extensionReferences.Select(r => string.Format("{2} {{ \"name\": \"{0}\", \"typeName\":\"{1}\"}}", r.Name, r.TypeName, Environment.NewLine));

MODIFY
tools/ExtensionsMetadataGenerator/test/ExtensionsMetadataGeneratorTests/ExtensionsMetadataGeneratorTests.cs
tools/ExtensionsMetadataGenerator/test/ExtensionsMetadataGeneratorTests/ExtensionsMetadataGeneratorTests.cs
@@ -36,5 +36,17 @@ public void GenerateExtensionsJson_Succeeds()
Assert.Equal("BarExtension", extensions[1]["name"]);
Assert.Equal(typeof(BarWebJobsStartup).AssemblyQualifiedName, extensions[1]["typeName"]);
}
+
+ [Theory]
+ [InlineData("System.Linq.dll", true)]
+ [InlineData("Microsoft.Azure.WebJobs.Extensions.dll", true)]
+ [InlineData("Microsoft.Azure.WebJobs.Extensions.Http.dll", true)]
+ [InlineData("microsoft.azure.webjobs.extensions.http.dll", true)]
+ [InlineData("Microsoft.Azure.EventGrid.dll", false)]
+ [InlineData("MyCoolExtension.dll", false)]
+ public void SomeAssembliesAreSkipped(string assemblyFileName, bool shouldSkip)
+ {
+ Assert.Equal(shouldSkip, ExtensionsMetadataGenerator.ExtensionsMetadataGenerator.AssemblyShouldBeSkipped(assemblyFileName));
+ }
}
}

Prevent built in extensions from being declared in extensions.json