Skip to content

Commit 2ee4017

Browse files
committed
Suppress generating source checksum attribute
Follow up to dotnet/aspnetcore#31089. Consume the new attribute to turn off generating source checksum attributes by default.
1 parent 415e585 commit 2ee4017

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/RazorSdk/SourceGenerators/RazorSourceGenerationContext.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using System.Diagnostics;
65
using System.Collections.Generic;
76
using System.Linq;
8-
using System.Threading;
97
using Microsoft.AspNetCore.Razor.Language;
108
using Microsoft.CodeAnalysis;
119

@@ -23,7 +21,6 @@ internal class RazorSourceGenerationContext
2321

2422
public RazorConfiguration Configuration { get; private set; }
2523

26-
2724
/// <summary>
2825
/// Gets a flag that determines if the source generator waits for the debugger to attach.
2926
/// <para>
@@ -34,13 +31,9 @@ internal class RazorSourceGenerationContext
3431
public bool WaitForDebugger { get; private set; }
3532

3633
/// <summary>
37-
/// Gets a flag that determine if the source generator should log verbose messages.
34+
/// Gets a flag that determines if generated Razor views and Pages includes the <c>RazorSourceChecksumAttribute</c>.
3835
/// </summary>
39-
/// <para>
40-
/// To configure this using MSBuild, use the <c>_RazorSourceGeneratorLog</c> property.
41-
/// For instance <c>dotnet msbuild /p:_RazorSourceGeneratorLog=true</c>
42-
/// </para>
43-
public bool EnableLogging { get; private set; }
36+
public bool GenerateMetadataSourceChecksumAttributes { get; private set; }
4437

4538
public RazorSourceGenerationContext(GeneratorExecutionContext context)
4639
{
@@ -67,7 +60,8 @@ public RazorSourceGenerationContext(GeneratorExecutionContext context)
6760
}
6861

6962
globalOptions.TryGetValue("build_property._RazorSourceGeneratorDebug", out var waitForDebugger);
70-
globalOptions.TryGetValue("build_property._RazorSourceGeneratorLog", out var enableLogging);
63+
64+
globalOptions.TryGetValue("build_property.GenerateRazorMetadataSourceChecksumAttributes", out var generateMetadataSourceChecksumAttributes);
7165

7266
var razorConfiguration = RazorConfiguration.Create(razorLanguageVersion, configurationName, Enumerable.Empty<RazorExtension>(), true);
7367
var (razorFiles, cshtmlFiles) = GetRazorInputs(context);
@@ -79,7 +73,7 @@ public RazorSourceGenerationContext(GeneratorExecutionContext context)
7973
RazorFiles = razorFiles;
8074
CshtmlFiles = cshtmlFiles;
8175
WaitForDebugger = waitForDebugger == "true";
82-
EnableLogging = enableLogging == "true";
76+
GenerateMetadataSourceChecksumAttributes = generateMetadataSourceChecksumAttributes == "true";
8377
}
8478

8579
private static VirtualRazorProjectFileSystem GetVirtualFileSystem(GeneratorExecutionContext context, IReadOnlyList<RazorInputItem> razorFiles, IReadOnlyList<RazorInputItem> cshtmlFiles)

src/RazorSdk/SourceGenerators/RazorSourceGenerator.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public void Execute(GeneratorExecutionContext context)
5656
b.Features.Add(new DefaultTypeNameFeature());
5757
b.SetRootNamespace(razorContext.RootNamespace);
5858

59+
b.Features.Add(new ConfigureRazorCodeGenerationOptions(options =>
60+
{
61+
options.SuppressMetadataSourceChecksumAttributes = !razorContext.GenerateMetadataSourceChecksumAttributes;
62+
}));
63+
5964
b.Features.Add(new StaticTagHelperFeature { TagHelpers = tagHelpers, });
6065
b.Features.Add(new DefaultTagHelperDescriptorProvider());
6166

src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.SourceGenerators.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Copyright (c) .NET Foundation. All rights reserved.
4141
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="CssScope" />
4242
<CompilerVisibleProperty Include="RazorLangVersion" />
4343
<CompilerVisibleProperty Include="RootNamespace" />
44+
<CompilerVisibleProperty Include="GenerateRazorMetadataSourceChecksumAttributes" />
4445
<CompilerVisibleProperty Include="MSBuildProjectDirectory" />
4546
<CompilerVisibleProperty Include="_RazorSourceGeneratorDebug" />
4647
<CompilerVisibleProperty Include="_RazorSourceGeneratorLog" />

0 commit comments

Comments
 (0)