Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Text;
using System.Text.Json;
using System.Threading;
Expand All @@ -22,6 +24,9 @@ internal sealed class Emitter
public string Emit(GeneratorExecutionContext context, IReadOnlyList<GeneratorFunctionMetadata> funcMetadata, bool includeAutoRegistrationCode)
{
string functionMetadataInfo = AddFunctionMetadataInfo(funcMetadata, context.CancellationToken);
Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
string generatorVersion = fileVersionInfo.ProductVersion;
Comment thread
satvu marked this conversation as resolved.
Outdated

return $$"""
// <auto-generated/>
Expand All @@ -41,6 +46,7 @@ namespace {{FunctionsUtil.GetNamespaceForGeneratedCode(context)}}
/// Custom <see cref="IFunctionMetadataProvider"/> implementation that returns function metadata definitions for the current worker."/>
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Azure.Functions.Worker.Sdk.Generators", "{{generatorVersion}}")]
public class GeneratedFunctionMetadataProvider : IFunctionMetadataProvider
{
/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace TestProject
/// Custom <see cref=""IFunctionMetadataProvider""/> implementation that returns function metadata definitions for the current worker.""/>
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Microsoft.Azure.Functions.Worker.Sdk.Generators"", ""1.1.4-local+5ee6e55d820a2ddfc019b1a57553560859c3d01b"")]
public class GeneratedFunctionMetadataProvider : IFunctionMetadataProvider
{{
/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.Azure.Functions.Worker.Sdk.Generators;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Testing;
using Xunit;

Expand All @@ -15,9 +18,14 @@ public partial class FunctionMetadataProviderGeneratorTests
public class IntegratedTriggersAndBindingsTests
{
private readonly Assembly[] _referencedExtensionAssemblies;
private readonly string _generatorVersion;

public IntegratedTriggersAndBindingsTests()
{
var generatorAssembly = Assembly.LoadFrom("Microsoft.Azure.Functions.Worker.Sdk.Generators.dll");
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(generatorAssembly.Location);
_generatorVersion = fileVersionInfo.ProductVersion!;

// load all extensions used in tests (match extensions tested on E2E app? Or include ALL extensions?)
var abstractionsExtension = Assembly.LoadFrom("Microsoft.Azure.Functions.Worker.Extensions.Abstractions.dll");
var httpExtension = Assembly.LoadFrom("Microsoft.Azure.Functions.Worker.Extensions.Http.dll");
Expand Down Expand Up @@ -94,7 +102,7 @@ public class MyOutputTypeNoHttpProp


string expectedGeneratedFileName = $"GeneratedFunctionMetadataProvider.g.cs";
string expectedOutput = """
string expectedOutput = $$"""
// <auto-generated/>
using System;
using System.Collections.Generic;
Expand All @@ -112,6 +120,7 @@ namespace TestProject
/// Custom <see cref="IFunctionMetadataProvider"/> implementation that returns function metadata definitions for the current worker."/>
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Azure.Functions.Worker.Sdk.Generators", "{{_generatorVersion}}")]
public class GeneratedFunctionMetadataProvider : IFunctionMetadataProvider
{
/// <inheritdoc/>
Expand Down Expand Up @@ -229,7 +238,7 @@ public class Book
""";

string expectedGeneratedFileName = $"GeneratedFunctionMetadataProvider.g.cs";
string expectedOutput = """
string expectedOutput = $$"""
// <auto-generated/>
using System;
using System.Collections.Generic;
Expand All @@ -247,6 +256,7 @@ namespace TestProject
/// Custom <see cref="IFunctionMetadataProvider"/> implementation that returns function metadata definitions for the current worker."/>
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Azure.Functions.Worker.Sdk.Generators", "{{_generatorVersion}}")]
public class GeneratedFunctionMetadataProvider : IFunctionMetadataProvider
{
/// <inheritdoc/>
Expand Down Expand Up @@ -339,7 +349,7 @@ public FakeAttribute(string name)
""";

string expectedGeneratedFileName = $"GeneratedFunctionMetadataProvider.g.cs";
string expectedOutput = """
string expectedOutput = $$"""
// <auto-generated/>
using System;
using System.Collections.Generic;
Expand All @@ -357,6 +367,7 @@ namespace TestProject
/// Custom <see cref="IFunctionMetadataProvider"/> implementation that returns function metadata definitions for the current worker."/>
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Azure.Functions.Worker.Sdk.Generators", "{{_generatorVersion}}")]
public class GeneratedFunctionMetadataProvider : IFunctionMetadataProvider
{
/// <inheritdoc/>
Expand Down Expand Up @@ -434,7 +445,7 @@ public Task RunTimer([TimerTrigger("0 0 0 * * *", RunOnStartup = false)] object
""";

string expectedGeneratedFileName = $"GeneratedFunctionMetadataProvider.g.cs";
string expectedOutput = """
string expectedOutput = $$"""
// <auto-generated/>
using System;
using System.Collections.Generic;
Expand All @@ -452,6 +463,7 @@ namespace TestProject
/// Custom <see cref="IFunctionMetadataProvider"/> implementation that returns function metadata definitions for the current worker."/>
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Azure.Functions.Worker.Sdk.Generators", "{{_generatorVersion}}")]
public class GeneratedFunctionMetadataProvider : IFunctionMetadataProvider
{
/// <inheritdoc/>
Expand Down Expand Up @@ -528,7 +540,7 @@ public Task<HttpResponseData> Http([HttpTrigger(AuthorizationLevel.Admin, "get",
""";

string expectedGeneratedFileName = $"GeneratedFunctionMetadataProvider.g.cs";
string expectedOutput = """
string expectedOutput = $$"""
// <auto-generated/>
using System;
using System.Collections.Generic;
Expand All @@ -546,6 +558,7 @@ namespace TestProject
/// Custom <see cref="IFunctionMetadataProvider"/> implementation that returns function metadata definitions for the current worker."/>
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Azure.Functions.Worker.Sdk.Generators", "{{_generatorVersion}}")]
public class GeneratedFunctionMetadataProvider : IFunctionMetadataProvider
{
/// <inheritdoc/>
Expand Down Expand Up @@ -632,7 +645,7 @@ public async Task<HttpResponseData> RunAsync2([HttpTrigger(AuthorizationLevel.An
""";

string expectedGeneratedFileName = $"GeneratedFunctionMetadataProvider.g.cs";
string expectedOutput = """
string expectedOutput = $$"""
// <auto-generated/>
using System;
using System.Collections.Generic;
Expand All @@ -650,6 +663,7 @@ namespace TestProject
/// Custom <see cref="IFunctionMetadataProvider"/> implementation that returns function metadata definitions for the current worker."/>
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Azure.Functions.Worker.Sdk.Generators", "{{_generatorVersion}}")]
public class GeneratedFunctionMetadataProvider : IFunctionMetadataProvider
{
/// <inheritdoc/>
Expand Down