Skip to content

Commit e483619

Browse files
Merge pull request #25 from daghb/master
Removed explicit loading of netstandard on Linux/OSX only
2 parents 72af675 + 7975beb commit e483619

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

RazorEngineCore/RazorEngineCompilationOptions.cs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22
using System.Reflection;
3+
using System.Runtime.InteropServices;
34
using Microsoft.CodeAnalysis;
45

56
namespace RazorEngineCore
67
{
78
public class RazorEngineCompilationOptions
89
{
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+
}
1936

2037
public HashSet<MetadataReference> MetadataReferences { get; set; } = new HashSet<MetadataReference>();
21-
38+
2239
public string TemplateNamespace { get; set; } = "TemplateNamespace";
2340
public string Inherits { get; set; } = "RazorEngineCore.RazorEngineTemplateBase";
2441

0 commit comments

Comments
 (0)