diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/SourceGenerators/RazorCohostingOptions.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/SourceGenerators/RazorCohostingOptions.cs
new file mode 100644
index 00000000000..fc1a8a78f1e
--- /dev/null
+++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/SourceGenerators/RazorCohostingOptions.cs
@@ -0,0 +1,9 @@
+namespace Microsoft.NET.Sdk.Razor.SourceGenerators;
+
+internal static class RazorCohostingOptions
+{
+ ///
+ /// True if razor is running in the cohosting mode
+ ///
+ internal static bool UseRazorCohostServer { get; set; } = false;
+}
diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/SourceGenerators/RazorSourceGenerator.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/SourceGenerators/RazorSourceGenerator.cs
index 5c1d6482e54..4c9c532c5ae 100644
--- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/SourceGenerators/RazorSourceGenerator.cs
+++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/SourceGenerators/RazorSourceGenerator.cs
@@ -19,8 +19,6 @@ public partial class RazorSourceGenerator : IIncrementalGenerator
{
private static RazorSourceGeneratorEventSource Log => RazorSourceGeneratorEventSource.Log;
- internal static bool UseRazorCohostServer { get; set; } = false;
-
// Testing usage only.
private readonly string? _testSuppressUniqueIds;
@@ -40,7 +38,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
var compilation = context.CompilationProvider;
// determine if we should suppress this run and filter out all the additional files and references if so
- var isGeneratorSuppressed = analyzerConfigOptions.CheckGlobalFlagSet("SuppressRazorSourceGenerator").Select((suppress, _) => !UseRazorCohostServer && suppress);
+ var isGeneratorSuppressed = analyzerConfigOptions.CheckGlobalFlagSet("SuppressRazorSourceGenerator").Select((suppress, _) => !RazorCohostingOptions.UseRazorCohostServer && suppress);
var additionalTexts = context.AdditionalTextsProvider.EmptyOrCachedWhen(isGeneratorSuppressed, true);
var metadataRefs = context.MetadataReferencesProvider.EmptyOrCachedWhen(isGeneratorSuppressed, true);
diff --git a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Initialization/RemoteLanguageServerFeatureOptions.cs b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Initialization/RemoteLanguageServerFeatureOptions.cs
index f056475e778..3a3965003cc 100644
--- a/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Initialization/RemoteLanguageServerFeatureOptions.cs
+++ b/src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Initialization/RemoteLanguageServerFeatureOptions.cs
@@ -20,21 +20,10 @@ public void SetOptions(RemoteClientInitializationOptions options)
{
_options = options;
- if (options.UseRazorCohostServer)
- {
- // ensure the source generator is in the correct mode
- SetGeneratorToCohostMode();
- }
+ // ensure the source generator is in the correct mode
+ RazorCohostingOptions.UseRazorCohostServer = options.UseRazorCohostServer;
}
- ///
- /// Sets the generator into cohosting mode.
- ///
- ///
- /// This is explicitly a separate method so that if not used we don't unnecessarily JIT any of the generator code.
- ///
- private static void SetGeneratorToCohostMode() => RazorSourceGenerator.UseRazorCohostServer = true;
-
public override bool SupportsFileManipulation => _options.SupportsFileManipulation;
public override string CSharpVirtualDocumentSuffix => throw new InvalidOperationException("This property is not valid in OOP");