Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix .NET8 for AOT / Single Executable #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ExampleAppNET8/ExampleAppNET8.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\RazorEngineCore\RazorEngineCore.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="template1.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="template2.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
58 changes: 58 additions & 0 deletions ExampleAppNET8/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using RazorEngineCore;

namespace ExampleAppNET5
{

class Program
{
static void Main(string[] args)
{
IRazorEngine razorEngine = new RazorEngine();
IRazorEngineCompiledTemplate template1 = razorEngine.Compile("Hello <h1>@Model.Name</h1>");

string result = template1.Run(new
{
Name = "<b>Alex</b>"
});

Console.WriteLine(result);
}


static void ReadFromFileAndRun()
{
IRazorEngine razorEngine = new RazorEngine();
string templateText = File.ReadAllText("template2.cshtml");

IRazorEngineCompiledTemplate template2 = razorEngine.Compile(templateText, builder =>
{
builder.IncludeDebuggingInfo();
});

if (!Directory.Exists("Temp"))
{
Directory.CreateDirectory("Temp");
}

template2.EnableDebugging("Temp");

string result = template2.Run(new
{
Name = "Alexander",
Items = new List<string>()
{
"item 1",
"item 2"
}
});

Console.WriteLine(result);
Console.ReadKey();
}
}
}
24 changes: 24 additions & 0 deletions ExampleAppNET8/template1.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Hello @Model.Name

@foreach(var item in @Model.Items)
{
<div>- @item</div>
}

<div data-name=""@Model.Name""></div>

<area>
@{ RecursionTest(3); }
</area>

@{
void RecursionTest(int level){
if (level <= 0)
{
return;
}

<div>LEVEL: @level</div>
@{ RecursionTest(level - 1); }
}
}
24 changes: 24 additions & 0 deletions ExampleAppNET8/template2.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div>
<h1>Hello</h1>

@{ Breakpoint(); }

@if (Model != null)
{
<h2>Hello @Model</h2>
}

<h3>111</h3>

@if (Model != null)
{
<h2>Hello @Model</h2>
}

<h3>111</h3>

@if (Model != null)
{
<h2>Hello @Model</h2>
}
</div>
6 changes: 3 additions & 3 deletions RazorEngineCore.Tests/RazorEngineCore.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions RazorEngineCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExampleAppNET472", "Example
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExampleAppNET5", "ExampleAppNET5\ExampleAppNET5.csproj", "{B19C090A-4EC1-441D-B702-ADD2ECA79198}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExampleAppNET8", "ExampleAppNET8\ExampleAppNET8.csproj", "{9E5835E0-F768-4ADE-9A1F-61FE6B411B8F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -44,6 +46,10 @@ Global
{B19C090A-4EC1-441D-B702-ADD2ECA79198}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B19C090A-4EC1-441D-B702-ADD2ECA79198}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B19C090A-4EC1-441D-B702-ADD2ECA79198}.Release|Any CPU.Build.0 = Release|Any CPU
{9E5835E0-F768-4ADE-9A1F-61FE6B411B8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9E5835E0-F768-4ADE-9A1F-61FE6B411B8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9E5835E0-F768-4ADE-9A1F-61FE6B411B8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9E5835E0-F768-4ADE-9A1F-61FE6B411B8F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 2 additions & 2 deletions RazorEngineCore/RazorEngineCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="6.0.25" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="6.0.31" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>
<PropertyGroup>
Expand Down