55
66namespace RazorEngineCore
77{
8+ using System ;
9+
10+ using Microsoft . CodeAnalysis . CSharp . Syntax ;
11+
812 public class RazorEngineCompilationOptions
913 {
10- public HashSet < Assembly > ReferencedAssemblies { get ; set ; } = new HashSet < Assembly > ( )
11- {
12- typeof ( object ) . Assembly ,
13- Assembly . Load ( new AssemblyName ( "Microsoft.CSharp" ) ) ,
14- typeof ( RazorEngineTemplateBase ) . Assembly ,
15- Assembly . Load ( new AssemblyName ( "System.Runtime" ) ) ,
16- Assembly . Load ( new AssemblyName ( "System.Linq" ) ) ,
17- Assembly . Load ( new AssemblyName ( "System.Linq.Expressions" ) )
18- } ;
14+ public HashSet < Assembly > ReferencedAssemblies { get ; set ; } = DefaultReferencedAssemblies ( ) ;
1915
2016 public HashSet < MetadataReference > MetadataReferences { get ; set ; } = new HashSet < MetadataReference > ( ) ;
2117 public string TemplateNamespace { get ; set ; } = "TemplateNamespace" ;
@@ -31,8 +27,44 @@ public RazorEngineCompilationOptions()
3127 // Loading netstandard explicitly causes runtime error on Linux/OSX
3228 if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
3329 {
34- this . ReferencedAssemblies . Add ( Assembly . Load ( new AssemblyName ( "netstandard" ) ) ) ;
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
38+ {
39+ this . ReferencedAssemblies . Add ( Assembly . Load ( new AssemblyName ( "netstandard" ) ) ) ;
40+ }
41+ }
42+ }
43+
44+ private static HashSet < Assembly > DefaultReferencedAssemblies ( )
45+ {
46+ if ( RuntimeInformation . FrameworkDescription . StartsWith ( ".NET Framework" , StringComparison . OrdinalIgnoreCase ) )
47+ {
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+ } ;
3557 }
58+
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+ } ;
3668 }
3769 }
3870}
0 commit comments