Skip to content

Commit c9f9e73

Browse files
committed
straightforward constructor for RazorEngineCompilationOptions,
cleanup
1 parent 97f4f94 commit c9f9e73

File tree

10 files changed

+55
-55
lines changed

10 files changed

+55
-55
lines changed
File renamed without changes.
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class TestModel : RazorEngineTemplateBase
1414
public IEnumerable<int> Items { get; set; }
1515
}
1616

17-
1817
class Program
1918
{
2019
static string Content = @"
@@ -48,15 +47,16 @@ static void Main(string[] args)
4847
IRazorEngine razorEngine = new RazorEngine();
4948
IRazorEngineCompiledTemplate template = razorEngine.Compile(Content);
5049

51-
string result = template.Run(new
52-
{
53-
Name = "Alexander",
54-
Items = new List<string>()
55-
{
56-
"item 1",
57-
"item 2"
58-
}
59-
});
50+
string result = template.Run(
51+
new
52+
{
53+
Name = "Alexander",
54+
Items = new List<string>()
55+
{
56+
"item 1",
57+
"item 2"
58+
}
59+
});
6060

6161
Console.WriteLine(result);
6262
Console.ReadKey();
File renamed without changes.

RazorEngineCore.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorEngineCore", "RazorEng
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorEngineCore.Tests", "RazorEngineCore.Tests\RazorEngineCore.Tests.csproj", "{86FE2C2C-868C-43B5-A134-0DC96F9F510A}"
99
EndProject
10-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExampleApp", "ExampleApp\ExampleApp.csproj", "{287FC29C-2C28-4168-8332-E1FF5BBB2721}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExampleAppCore", "ExampleApp\ExampleAppCore.csproj", "{287FC29C-2C28-4168-8332-E1FF5BBB2721}"
1111
EndProject
1212
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DF4FC1D4-CE2B-4653-A54B-827EC9533666}"
1313
ProjectSection(SolutionItems) = preProject
1414
Pack.ps1 = Pack.ps1
1515
EndProjectSection
1616
EndProject
17-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleFrameworkApp", "ExampleFrameworkApp\ExampleFrameworkApp.csproj", "{D27C1578-BFF9-4469-9099-DAF64450BBBE}"
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleAppNET472", "ExampleFrameworkApp\ExampleAppNET472.csproj", "{D27C1578-BFF9-4469-9099-DAF64450BBBE}"
1818
EndProject
1919
Global
2020
GlobalSection(SolutionConfigurationPlatforms) = preSolution

RazorEngineCore/RazorEngineCompilationOptions.cs

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
using System.Reflection;
33
using System.Runtime.InteropServices;
44
using Microsoft.CodeAnalysis;
5+
using System;
56

67
namespace 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
}

RazorEngineCore/RazorEngineCore.csproj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
<TargetFramework>netstandard2.0</TargetFramework>
44
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
55
<Version>2020.6.1</Version>
6-
<Authors>Alexander Selishchev, Simon Mourier, William David Cossey, Benjamin Smith, Dag H. Baardsen</Authors>
6+
<Authors>Alexander Selishchev, Simon Mourier, William David Cossey, Benjamin Smith, Dag H. Baardsen, krmr</Authors>
77
<PackageProjectUrl>https://github.com/adoconnection/RazorEngineCore</PackageProjectUrl>
88
<Description>ASP.NET Core 3.1 Razor Template Engine</Description>
9-
<AssemblyVersion>2020.6.1.0</AssemblyVersion>
10-
<FileVersion>2020.6.1.0</FileVersion>
11-
<PackageReleaseNotes>– Add support for loading assemblies through MetadataReference
12-
– Microsoft.AspNetCore.Razor.Language update to 3.1.5
13-
– expose generated code in RazorEngineCompilationException</PackageReleaseNotes>
9+
<AssemblyVersion>2020.9.1.0</AssemblyVersion>
10+
<FileVersion>2020.9.1.0</FileVersion>
11+
<PackageReleaseNotes>– .NET 4.7.2 support</PackageReleaseNotes>
12+
<Company>Alexander Selishchev, Simon Mourier, William David Cossey, Benjamin Smith, Dag H. Baardsen, krmr</Company>
1413
</PropertyGroup>
1514
<ItemGroup>
1615
<PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="3.1.5" />

0 commit comments

Comments
 (0)