22using System . Reflection ;
33using System . Runtime . InteropServices ;
44using Microsoft . CodeAnalysis ;
5+ using System ;
56
67namespace RazorEngineCore
78{
8- using System ;
99
10- using Microsoft . CodeAnalysis . CSharp . Syntax ;
1110
1211 public class RazorEngineCompilationOptions
1312 {
14- public HashSet < Assembly > ReferencedAssemblies { get ; set ; } = DefaultReferencedAssemblies ( ) ;
13+ public HashSet < Assembly > ReferencedAssemblies { get ; set ; }
1514
1615 public HashSet < MetadataReference > MetadataReferences { get ; set ; } = new HashSet < MetadataReference > ( ) ;
1716 public string TemplateNamespace { get ; set ; } = "TemplateNamespace" ;
@@ -24,47 +23,49 @@ public class RazorEngineCompilationOptions
2423
2524 public RazorEngineCompilationOptions ( )
2625 {
27- // Loading netstandard explicitly causes runtime error on Linux/OSX
28- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
26+ bool isWindows = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ;
27+ bool isFullFramework = RuntimeInformation . FrameworkDescription . StartsWith ( ".NET Framework" , StringComparison . OrdinalIgnoreCase ) ;
28+
29+ if ( isWindows && isFullFramework )
2930 {
30- if ( RuntimeInformation . FrameworkDescription . StartsWith ( ".NET Framework" , StringComparison . OrdinalIgnoreCase ) )
31- {
32- this . ReferencedAssemblies . Add (
33- Assembly . Load (
34- new AssemblyName (
35- "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" ) ) ) ;
36- }
37- else
31+ this . ReferencedAssemblies = new HashSet < Assembly > ( )
3832 {
39- this . ReferencedAssemblies . Add ( Assembly . Load ( new AssemblyName ( "netstandard" ) ) ) ;
40- }
33+ typeof ( object ) . Assembly ,
34+ Assembly . Load ( new AssemblyName ( "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" ) ) ,
35+ typeof ( RazorEngineTemplateBase ) . Assembly ,
36+ typeof ( System . Runtime . GCSettings ) . Assembly ,
37+ typeof ( System . Linq . Enumerable ) . Assembly ,
38+ typeof ( System . Linq . Expressions . Expression ) . Assembly ,
39+ Assembly . Load ( new AssemblyName ( "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" ) )
40+ } ;
4141 }
42- }
4342
44- private static HashSet < Assembly > DefaultReferencedAssemblies ( )
45- {
46- if ( RuntimeInformation . FrameworkDescription . StartsWith ( ".NET Framework" , StringComparison . OrdinalIgnoreCase ) )
43+ if ( isWindows && ! isFullFramework ) // i.e. NETCore
4744 {
48- return new HashSet < Assembly > ( )
49- {
50- typeof ( object ) . Assembly ,
51- Assembly . Load ( new AssemblyName ( "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" ) ) ,
52- typeof ( RazorEngineTemplateBase ) . Assembly ,
53- typeof ( System . Runtime . GCSettings ) . Assembly ,
54- typeof ( System . Linq . Enumerable ) . Assembly ,
55- typeof ( System . Linq . Expressions . Expression ) . Assembly
56- } ;
45+ this . ReferencedAssemblies = new HashSet < Assembly > ( )
46+ {
47+ typeof ( object ) . Assembly ,
48+ Assembly . Load ( new AssemblyName ( "Microsoft.CSharp" ) ) ,
49+ typeof ( RazorEngineTemplateBase ) . Assembly ,
50+ Assembly . Load ( new AssemblyName ( "System.Runtime" ) ) ,
51+ Assembly . Load ( new AssemblyName ( "System.Linq" ) ) ,
52+ Assembly . Load ( new AssemblyName ( "System.Linq.Expressions" ) ) ,
53+ Assembly . Load ( new AssemblyName ( "netstandard" ) )
54+ } ;
5755 }
5856
59- return new HashSet < Assembly > ( )
60- {
61- typeof ( object ) . Assembly ,
62- Assembly . Load ( new AssemblyName ( "Microsoft.CSharp" ) ) ,
63- typeof ( RazorEngineTemplateBase ) . Assembly ,
64- Assembly . Load ( new AssemblyName ( "System.Runtime" ) ) ,
65- Assembly . Load ( new AssemblyName ( "System.Linq" ) ) ,
66- Assembly . Load ( new AssemblyName ( "System.Linq.Expressions" ) )
67- } ;
57+ if ( ! isWindows )
58+ {
59+ this . ReferencedAssemblies = new HashSet < Assembly > ( )
60+ {
61+ typeof ( object ) . Assembly ,
62+ Assembly . Load ( new AssemblyName ( "Microsoft.CSharp" ) ) ,
63+ typeof ( RazorEngineTemplateBase ) . Assembly ,
64+ Assembly . Load ( new AssemblyName ( "System.Runtime" ) ) ,
65+ Assembly . Load ( new AssemblyName ( "System.Linq" ) ) ,
66+ Assembly . Load ( new AssemblyName ( "System.Linq.Expressions" ) )
67+ } ;
68+ }
6869 }
6970 }
7071}
0 commit comments