diff --git a/src/RazorSdk/SourceGenerators/RazorSourceGenerationContext.cs b/src/RazorSdk/SourceGenerators/RazorSourceGenerationContext.cs index 0dea240e48fc..ace40fe53b03 100644 --- a/src/RazorSdk/SourceGenerators/RazorSourceGenerationContext.cs +++ b/src/RazorSdk/SourceGenerators/RazorSourceGenerationContext.cs @@ -2,10 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics; using System.Collections.Generic; using System.Linq; -using System.Threading; using Microsoft.AspNetCore.Razor.Language; using Microsoft.CodeAnalysis; @@ -23,7 +21,6 @@ internal class RazorSourceGenerationContext public RazorConfiguration Configuration { get; private set; } - /// /// Gets a flag that determines if the source generator waits for the debugger to attach. /// @@ -34,13 +31,9 @@ internal class RazorSourceGenerationContext public bool WaitForDebugger { get; private set; } /// - /// Gets a flag that determine if the source generator should log verbose messages. + /// Gets a flag that determines if generated Razor views and Pages includes the RazorSourceChecksumAttribute. /// - /// - /// To configure this using MSBuild, use the _RazorSourceGeneratorLog property. - /// For instance dotnet msbuild /p:_RazorSourceGeneratorLog=true - /// - public bool EnableLogging { get; private set; } + public bool GenerateMetadataSourceChecksumAttributes { get; private set; } public RazorSourceGenerationContext(GeneratorExecutionContext context) { @@ -67,7 +60,8 @@ public RazorSourceGenerationContext(GeneratorExecutionContext context) } globalOptions.TryGetValue("build_property._RazorSourceGeneratorDebug", out var waitForDebugger); - globalOptions.TryGetValue("build_property._RazorSourceGeneratorLog", out var enableLogging); + + globalOptions.TryGetValue("build_property.GenerateRazorMetadataSourceChecksumAttributes", out var generateMetadataSourceChecksumAttributes); var razorConfiguration = RazorConfiguration.Create(razorLanguageVersion, configurationName, Enumerable.Empty(), true); var (razorFiles, cshtmlFiles) = GetRazorInputs(context); @@ -79,7 +73,7 @@ public RazorSourceGenerationContext(GeneratorExecutionContext context) RazorFiles = razorFiles; CshtmlFiles = cshtmlFiles; WaitForDebugger = waitForDebugger == "true"; - EnableLogging = enableLogging == "true"; + GenerateMetadataSourceChecksumAttributes = generateMetadataSourceChecksumAttributes == "true"; } private static VirtualRazorProjectFileSystem GetVirtualFileSystem(GeneratorExecutionContext context, IReadOnlyList razorFiles, IReadOnlyList cshtmlFiles) diff --git a/src/RazorSdk/SourceGenerators/RazorSourceGenerator.cs b/src/RazorSdk/SourceGenerators/RazorSourceGenerator.cs index 7a6f9ac82552..7ac1851efa62 100644 --- a/src/RazorSdk/SourceGenerators/RazorSourceGenerator.cs +++ b/src/RazorSdk/SourceGenerators/RazorSourceGenerator.cs @@ -56,6 +56,11 @@ public void Execute(GeneratorExecutionContext context) b.Features.Add(new DefaultTypeNameFeature()); b.SetRootNamespace(razorContext.RootNamespace); + b.Features.Add(new ConfigureRazorCodeGenerationOptions(options => + { + options.SuppressMetadataSourceChecksumAttributes = !razorContext.GenerateMetadataSourceChecksumAttributes; + })); + b.Features.Add(new StaticTagHelperFeature { TagHelpers = tagHelpers, }); b.Features.Add(new DefaultTagHelperDescriptorProvider()); diff --git a/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.SourceGenerators.targets b/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.SourceGenerators.targets index eb335583037a..cc6fdf130bd2 100644 --- a/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.SourceGenerators.targets +++ b/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.SourceGenerators.targets @@ -41,6 +41,7 @@ Copyright (c) .NET Foundation. All rights reserved. +