|
1 | | -using System.Collections.Generic; |
| 1 | +using System.Collections.Generic; |
2 | 2 | using System.Reflection; |
| 3 | +using System.Runtime.InteropServices; |
3 | 4 | using Microsoft.CodeAnalysis; |
4 | 5 |
|
5 | 6 | namespace RazorEngineCore |
6 | 7 | { |
7 | 8 | public class RazorEngineCompilationOptions |
8 | 9 | { |
9 | | - public HashSet<Assembly> ReferencedAssemblies { get; set; } = new HashSet<Assembly>() |
10 | | - { |
11 | | - typeof(object).Assembly, |
12 | | - Assembly.Load(new AssemblyName("Microsoft.CSharp")), |
13 | | - typeof(RazorEngineTemplateBase).Assembly, |
14 | | - Assembly.Load(new AssemblyName("netstandard")), |
15 | | - Assembly.Load(new AssemblyName("System.Runtime")), |
16 | | - Assembly.Load(new AssemblyName("System.Linq")), |
17 | | - Assembly.Load(new AssemblyName("System.Linq.Expressions")) |
18 | | - }; |
| 10 | + private HashSet<Assembly> _referencedAssemblies; |
| 11 | + public HashSet<Assembly> ReferencedAssemblies { |
| 12 | + get |
| 13 | + { |
| 14 | + if (this._referencedAssemblies != null) |
| 15 | + return this._referencedAssemblies; |
| 16 | + |
| 17 | + this._referencedAssemblies = new HashSet<Assembly>() |
| 18 | + { |
| 19 | + typeof(object).Assembly, |
| 20 | + Assembly.Load(new AssemblyName("Microsoft.CSharp")), |
| 21 | + typeof(RazorEngineTemplateBase).Assembly, |
| 22 | + Assembly.Load(new AssemblyName("System.Runtime")), |
| 23 | + Assembly.Load(new AssemblyName("System.Linq")), |
| 24 | + Assembly.Load(new AssemblyName("System.Linq.Expressions")) |
| 25 | + }; |
| 26 | + |
| 27 | + // Loading netstandard explicitly causes runtime error on Linux/OSX |
| 28 | + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
| 29 | + { |
| 30 | + this._referencedAssemblies.Add(Assembly.Load(new AssemblyName("netstandard"))); |
| 31 | + } |
| 32 | + |
| 33 | + return this._referencedAssemblies; |
| 34 | + } |
| 35 | + } |
19 | 36 |
|
20 | 37 | public HashSet<MetadataReference> MetadataReferences { get; set; } = new HashSet<MetadataReference>(); |
21 | | - |
| 38 | + |
22 | 39 | public string TemplateNamespace { get; set; } = "TemplateNamespace"; |
23 | 40 | public string Inherits { get; set; } = "RazorEngineCore.RazorEngineTemplateBase"; |
24 | 41 |
|
|
0 commit comments