IL.VirtualViews
1.2.0
See the version list below for details.
dotnet add package IL.VirtualViews --version 1.2.0
NuGet\Install-Package IL.VirtualViews -Version 1.2.0
<PackageReference Include="IL.VirtualViews" Version="1.2.0" />
paket add IL.VirtualViews --version 1.2.0
#r "nuget: IL.VirtualViews, 1.2.0"
// Install IL.VirtualViews as a Cake Addin #addin nuget:?package=IL.VirtualViews&version=1.2.0 // Install IL.VirtualViews as a Cake Tool #tool nuget:?package=IL.VirtualViews&version=1.2.0
IL.VirtualViews
Library which allows virtually register *.cshtml file as .cs classes with special attributes.
How to use
- Reference IL.VirtualViews in your project
- Use registration extensions coming with library to activate functionality:
(IServiceCollection)services.AddVirtualViewsCapabilities()
or(WebApplicationBuilder)builder.AddVirtualViewsCapabilities()
- Use
[VirtualViewPath("")]
attribute for your classes with path to a view you want to register virtually - Derive your class from
IVirtualView
interface and implement the content which view is supposed to have
Examples
[VirtualViewPath("/Views/Test.cshtml")]
class Sample : IVirtualView
{
public string ViewContent =>
"""
@model string
@Html.Raw(Model)
""";
}
Virtual cshtml
There a support for .virtual.cshtml files that have build action Additional Files
.
Following location of such file there will be generated partial *.cs
file with same name as source *.virtual.cshtml
file.
Autogenerated file will automatically have all the content that you have populated in .virtual.cshtml
, so that you can only introduce your own(not source generated) partial part and decorate it with VirtualViewPath
attribute.
Sample
/Test/Test.virtual.cshtml
addded to solution with build action = Additional Files
and with content
@model string
@Html.Raw(Model)
will produce source generated file Test.g.cs
:
// <auto-generated />
using IL.VirtualViews.Interfaces;
namespace VirtualViews;
public partial class Test : IVirtualView
{
public string ViewContent()
{
return@"
@model string
@Html.Raw(Model)
";
}
}
Then you only need to create non-auto-generated partial part and decorate it with VirtualViewPath
attribute with desired path original view was supposed to be handled for.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- IL.Misc (>= 1.1.1)
- IL.VirtualViews.Generation (>= 1.2.0)
- Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation (>= 6.0.32)
-
net7.0
- IL.Misc (>= 1.1.1)
- IL.VirtualViews.Generation (>= 1.2.0)
- Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation (>= 7.0.20)
-
net8.0
- IL.Misc (>= 1.1.1)
- IL.VirtualViews.Generation (>= 1.2.0)
- Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation (>= 8.0.6)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on IL.VirtualViews:
Package | Downloads |
---|---|
IL.RulesBasedOutputCache
Rules based output cache. |
GitHub repositories
This package is not used by any popular GitHub repositories.