Skip to content

Instantly share code, notes, and snippets.

@brad-jones
Created September 5, 2017 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brad-jones/82495e4e3cb3ad3c5b205103f37ad604 to your computer and use it in GitHub Desktop.
Save brad-jones/82495e4e3cb3ad3c5b205103f37ad604 to your computer and use it in GitHub Desktop.
Intial setup for RazorLight dotnet 2.0
using System;
using Xunit;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Extensions;
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.AspNetCore.Mvc.Razor.Extensions;
namespace Tests.Razor
{
public class RazorTests
{
[Fact]
public void RazorTest()
{
var engine = RazorEngine.Create(builder => RazorExtensions.Register(builder));
var project = RazorProject.Create("./Razor/Templates");
var templateEngine = new RazorTemplateEngine(engine, project);
var cSharpDocument = templateEngine.GenerateCode("HelloWorld.cshtml");
Console.WriteLine("Code: " + cSharpDocument.GeneratedCode);
// next compile with roslyn
// see: https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.Razor/Internal/CSharpCompiler.cs
// see: https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.Razor/Internal/RazorViewCompiler.cs
// then basically call the generated assembly with reflection
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment