Skip to content

Suppress generating source checksum attribute #16468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions src/RazorSdk/SourceGenerators/RazorSourceGenerationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -23,7 +21,6 @@ internal class RazorSourceGenerationContext

public RazorConfiguration Configuration { get; private set; }


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

/// <summary>
/// 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 <c>RazorSourceChecksumAttribute</c>.
/// </summary>
/// <para>
/// To configure this using MSBuild, use the <c>_RazorSourceGeneratorLog</c> property.
/// For instance <c>dotnet msbuild /p:_RazorSourceGeneratorLog=true</c>
/// </para>
public bool EnableLogging { get; private set; }
public bool GenerateMetadataSourceChecksumAttributes { get; private set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this also a replacement for logging ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unused


public RazorSourceGenerationContext(GeneratorExecutionContext context)
{
Expand All @@ -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<RazorExtension>(), true);
var (razorFiles, cshtmlFiles) = GetRazorInputs(context);
Expand All @@ -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<RazorInputItem> razorFiles, IReadOnlyList<RazorInputItem> cshtmlFiles)
Expand Down
5 changes: 5 additions & 0 deletions src/RazorSdk/SourceGenerators/RazorSourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="CssScope" />
<CompilerVisibleProperty Include="RazorLangVersion" />
<CompilerVisibleProperty Include="RootNamespace" />
<CompilerVisibleProperty Include="GenerateRazorMetadataSourceChecksumAttributes" />
<CompilerVisibleProperty Include="MSBuildProjectDirectory" />
<CompilerVisibleProperty Include="_RazorSourceGeneratorDebug" />
<CompilerVisibleProperty Include="_RazorSourceGeneratorLog" />
Expand Down