14
14
using System . Threading . Tasks ;
15
15
using Microsoft . CodeAnalysis . Collections ;
16
16
using Microsoft . CodeAnalysis . Host . Mef ;
17
+ using Microsoft . CodeAnalysis . Options ;
17
18
using Microsoft . CodeAnalysis . PooledObjects ;
18
19
using Microsoft . CodeAnalysis . Shared . Extensions ;
19
20
using Roslyn . Utilities ;
@@ -28,17 +29,13 @@ namespace Microsoft.CodeAnalysis.Host;
28
29
internal sealed class CompileTimeSolutionProvider : ICompileTimeSolutionProvider
29
30
{
30
31
[ ExportWorkspaceServiceFactory ( typeof ( ICompileTimeSolutionProvider ) , [ WorkspaceKind . Host ] ) , Shared ]
31
- private sealed class Factory : IWorkspaceServiceFactory
32
+ [ method: ImportingConstructor ]
33
+ [ method: Obsolete ( MefConstruction . ImportingConstructorMessage , error : true ) ]
34
+ private sealed class Factory ( IGlobalOptionService globalOptions ) : IWorkspaceServiceFactory
32
35
{
33
- [ ImportingConstructor ]
34
- [ Obsolete ( MefConstruction . ImportingConstructorMessage , error : true ) ]
35
- public Factory ( )
36
- {
37
- }
38
-
39
36
[ Obsolete ( MefConstruction . FactoryMethodMessage , error : true ) ]
40
37
public IWorkspaceService CreateService ( HostWorkspaceServices workspaceServices )
41
- => new CompileTimeSolutionProvider ( workspaceServices . Workspace ) ;
38
+ => new CompileTimeSolutionProvider ( workspaceServices . Workspace , globalOptions ) ;
42
39
}
43
40
44
41
private const string RazorEncConfigFileName = "RazorSourceGenerator.razorencconfig" ;
@@ -52,6 +49,8 @@ public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
52
49
private static readonly ImmutableArray < string > s_razorSourceGeneratorFileNamePrefixes = s_razorSourceGeneratorAssemblyNames
53
50
. SelectAsArray ( static assemblyName => Path . Combine ( assemblyName , RazorSourceGeneratorTypeName ) ) ;
54
51
52
+ private readonly bool _useCohosting ;
53
+
55
54
private readonly object _gate = new ( ) ;
56
55
57
56
/// <summary>
@@ -65,8 +64,9 @@ public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
65
64
66
65
private Solution ? _lastCompileTimeSolution ;
67
66
68
- public CompileTimeSolutionProvider ( Workspace workspace )
67
+ public CompileTimeSolutionProvider ( Workspace workspace , IGlobalOptionService globalOptions )
69
68
{
69
+ _useCohosting = globalOptions . GetOption ( LegacyRazorOptions . UseCohosting ) ;
70
70
_ = workspace . RegisterWorkspaceChangedHandler ( ( e ) =>
71
71
{
72
72
if ( e . Kind is WorkspaceChangeKind . SolutionCleared or WorkspaceChangeKind . SolutionRemoved )
@@ -89,6 +89,12 @@ private static bool IsRazorAnalyzerConfig(TextDocumentState documentState)
89
89
90
90
public Solution GetCompileTimeSolution ( Solution designTimeSolution )
91
91
{
92
+ if ( _useCohosting )
93
+ {
94
+ // when cohosting is on, the design time and runtime solutions are the same
95
+ return designTimeSolution ;
96
+ }
97
+
92
98
lock ( _gate )
93
99
{
94
100
_designTimeToCompileTimeSolution . TryGetValue ( designTimeSolution , out var cachedCompileTimeSolution ) ;
0 commit comments