Skip to content

Commit 624b37d

Browse files
authored
Filtering CSX metdatada reference resolution (#7334)
1 parent f5b19f5 commit 624b37d

File tree

1 file changed

+48
-30
lines changed

1 file changed

+48
-30
lines changed

src/WebJobs.Script/Description/DotNet/ScriptFunctionMetadataResolver.cs

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,38 +39,51 @@ public sealed class ScriptFunctionMetadataResolver : MetadataReferenceResolver,
3939
private MetadataReferenceResolver _scriptResolver;
4040

4141
private static readonly string[] DefaultAssemblyReferences =
42-
{
43-
typeof(ILoggerFactory).Assembly.Location, /*Microsoft.Extensions.Logging.Abstractions*/
44-
typeof(IAsyncCollector<>).Assembly.Location, /*Microsoft.Azure.WebJobs*/
45-
typeof(JobHost).Assembly.Location, /*Microsoft.Azure.WebJobs.Host*/
46-
typeof(WebJobs.Extensions.ExtensionsWebJobsStartup).Assembly.Location, /*Microsoft.Azure.WebJobs.Extensions*/
47-
typeof(AspNetCore.Http.HttpRequest).Assembly.Location, /*Microsoft.AspNetCore.Http.Abstractions*/
48-
typeof(AspNetCore.Mvc.IActionResult).Assembly.Location, /*Microsoft.AspNetCore.Mvc.Abstractions*/
49-
typeof(AspNetCore.Mvc.RedirectResult).Assembly.Location, /*Microsoft.AspNetCore.Mvc.Core*/
50-
typeof(AspNetCore.Http.IQueryCollection).Assembly.Location, /*Microsoft.AspNetCore.Http.Features*/
51-
typeof(Microsoft.Extensions.Primitives.StringValues).Assembly.Location, /*Microsoft.Extensions.Primitives*/
52-
typeof(System.Net.Http.HttpClientExtensions).Assembly.Location /*System.Net.Http.Formatting*/
53-
};
42+
{
43+
typeof(ILoggerFactory).Assembly.Location, /*Microsoft.Extensions.Logging.Abstractions*/
44+
typeof(IAsyncCollector<>).Assembly.Location, /*Microsoft.Azure.WebJobs*/
45+
typeof(JobHost).Assembly.Location, /*Microsoft.Azure.WebJobs.Host*/
46+
typeof(WebJobs.Extensions.ExtensionsWebJobsStartup).Assembly.Location, /*Microsoft.Azure.WebJobs.Extensions*/
47+
typeof(AspNetCore.Http.HttpRequest).Assembly.Location, /*Microsoft.AspNetCore.Http.Abstractions*/
48+
typeof(AspNetCore.Mvc.IActionResult).Assembly.Location, /*Microsoft.AspNetCore.Mvc.Abstractions*/
49+
typeof(AspNetCore.Mvc.RedirectResult).Assembly.Location, /*Microsoft.AspNetCore.Mvc.Core*/
50+
typeof(AspNetCore.Http.IQueryCollection).Assembly.Location, /*Microsoft.AspNetCore.Http.Features*/
51+
typeof(Microsoft.Extensions.Primitives.StringValues).Assembly.Location, /*Microsoft.Extensions.Primitives*/
52+
typeof(System.Net.Http.HttpClientExtensions).Assembly.Location /*System.Net.Http.Formatting*/
53+
};
5454

5555
private static readonly List<ISharedAssemblyProvider> SharedAssemblyProviders = new List<ISharedAssemblyProvider>
56-
{
57-
new DirectSharedAssemblyProvider(typeof(Newtonsoft.Json.JsonConvert).Assembly), /* Newtonsoft.Json */
58-
new DirectSharedAssemblyProvider(typeof(Microsoft.WindowsAzure.Storage.StorageUri).Assembly), /* Microsoft.WindowsAzure.Storage */
59-
};
56+
{
57+
new DirectSharedAssemblyProvider(typeof(Newtonsoft.Json.JsonConvert).Assembly), /* Newtonsoft.Json */
58+
new DirectSharedAssemblyProvider(typeof(Microsoft.WindowsAzure.Storage.StorageUri).Assembly), /* Microsoft.WindowsAzure.Storage */
59+
};
6060

6161
private static readonly string[] DefaultNamespaceImports =
62-
{
63-
"System",
64-
"System.Collections.Generic",
65-
"System.IO",
66-
"System.Linq",
67-
"System.Net.Http",
68-
"System.Threading.Tasks",
69-
"Microsoft.Azure.WebJobs",
70-
"Microsoft.Azure.WebJobs.Host",
71-
"Microsoft.Extensions.Logging",
72-
"Microsoft.AspNetCore.Http"
73-
};
62+
{
63+
"System",
64+
"System.Collections.Generic",
65+
"System.IO",
66+
"System.Linq",
67+
"System.Net.Http",
68+
"System.Threading.Tasks",
69+
"Microsoft.Azure.WebJobs",
70+
"Microsoft.Azure.WebJobs.Host",
71+
"Microsoft.Extensions.Logging",
72+
"Microsoft.AspNetCore.Http"
73+
};
74+
75+
private static readonly string[] PrivateHostAssemblies =
76+
{
77+
"Azure.Core",
78+
"Azure.Identity",
79+
"Azure.Storage.Blobs",
80+
"Azure.Storage.Common",
81+
"Microsoft.Azure.WebJobs.StorageProvider.Blobs",
82+
"Microsoft.Bcl.AsyncInterfaces",
83+
"Microsoft.Extensions.Azure",
84+
"Microsoft.Identity.Client",
85+
"Microsoft.Identity.Client.Extensions.Msal"
86+
};
7487

7588
public ScriptFunctionMetadataResolver(string scriptFilePath, ICollection<IScriptBindingProvider> bindingProviders, ILogger logger)
7689
{
@@ -157,8 +170,13 @@ public override ImmutableArray<PortableExecutableReference> ResolveReference(str
157170

158171
if (!HasValidAssemblyFileExtension(reference))
159172
{
160-
// Try to resolve using the default resolver (framework assemblies, e.g. System.Core, System.Xml, etc.)
161-
ImmutableArray<PortableExecutableReference> result = _scriptResolver.ResolveReference(reference, baseFilePath, properties);
173+
ImmutableArray<PortableExecutableReference> result = ImmutableArray<PortableExecutableReference>.Empty;
174+
175+
if (!PrivateHostAssemblies.Contains(reference))
176+
{
177+
// Try to resolve using the default resolver (framework assemblies, e.g. System.Core, System.Xml, etc.)
178+
result = _scriptResolver.ResolveReference(reference, baseFilePath, properties);
179+
}
162180

163181
// If the default script resolver can't resolve the assembly
164182
// check if this is one of host's shared assemblies

0 commit comments

Comments
 (0)