Skip to content

Commit 296c9bd

Browse files
committed
Documentation update
1 parent 418cd35 commit 296c9bd

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# MSBuild Razor Compiler
22

3+
[![Build status](https://ci.appveyor.com/api/projects/status/yndlxwfnxom60n1s?svg=true)](https://ci.appveyor.com/project/MRCollective/msbuildrazorcompiler)
4+
[![NuGet version](https://img.shields.io/nuget/vpre/MSBuildRazorCompiler.svg)](https://www.nuget.org/packages/MSBuildRazorCompiler)
5+
36
This library provides a .NET Core 3.1 compatible MSBuild task that will automatically compile all `.cshtml` files into `.cs` files in-place and also provides you code you can call to then invoke those classes with a model and get the resulting output.
47

58
This library is inspired by [RazorGenerator](https://github.com/RazorGenerator/RazorGenerator), which was a custom tool for Visual Studio that created a compiled `.cs` file when saving a `.cshtml` file in your IDE. This was handy for situations where you want to have static template files (e.g. email templates, [library templates](https://github.com/MRCollective/ChameleonForms/tree/master/ChameleonForms/Templates/Default), etc.). RazorGenerator doesn't support .NET Core, hence creating this.
@@ -9,11 +12,19 @@ This library is implemented by providing a thin wrapper over the [RazorLight](ht
912
1. Compilation of `.cshtml` files to `.cs` files - this happens just before the `CoreCompile` task of the project you install this library into via the included MSBuild task.
1013
2. Rendering / invocation of the resultant `.cs` code
1114

12-
Because this library generates `.cs` files you don't need to worry about compilation performance, runtime compilation errors or caching or anything like that. It also allows you to have predictability of having real classes you can reference from your code rahter rather than relying on magic strings to find your `.cshtml` files and needing to either ship your `.cshtml` files with your code or embed them into your dll. Using this solution those files are only used at compile time and can then be discarded.
15+
Because this library generates `.cs` files you don't need to worry about compilation performance, runtime compilation errors, caching, etc. It also allows you to have the predictability of having real classes you can reference from your code rather than relying on magic strings to find your `.cshtml` files and needing to either ship your `.cshtml` files with your code or embed them into your dll. Using this solution those files are only used at compile time and can then be discarded.
1316

1417
## Getting started
1518

16-
1. Include `SomeFile.cshtml` files in your (.netcore3.1) project
17-
2. `Install-Package `MSBuildRazorCompiler` (work-in-progress, not in nuget.org yet)
18-
3. Compile - you should now see `some-file.cshtml.generated.cs` next to it with a class `SomeFile` in the namespace of your project
19-
4. Execute the following code to get a rendered result: `new SomeFile().Render(model, viewBag or null)` - there is also an async variant
19+
1. Include `SomeFile.cshtml` in your (netcoreapp3.1) project
20+
2. `Install-Package MSBuildRazorCompiler`
21+
3. Compile - you should now see `SomeFile.cshtml.generated.cs` next to your `SomeFile.cshtml`, this new file will contain a class `SomeFile` that extends `RazorLight.TemplatePage<TModel>` and will be in the namespace of your project at the folder level your file was in
22+
4. Execute the following code to get a rendered result (note: you'll need to add a `using RazorRenderer;`): `new SomeFile().Render(model, viewBag or null)` - there is also an async variant
23+
24+
## Intellisense
25+
26+
For intellisense to work it's recommended you add the following to the top of your file:
27+
28+
```cshtml
29+
@inherits RazorLight.TemplatePage<MyModelType>
30+
```

0 commit comments

Comments
 (0)