IL.VirtualViews 2.0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package IL.VirtualViews --version 2.0.0.1
                    
NuGet\Install-Package IL.VirtualViews -Version 2.0.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IL.VirtualViews" Version="2.0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IL.VirtualViews" Version="2.0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="IL.VirtualViews" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add IL.VirtualViews --version 2.0.0.1
                    
#r "nuget: IL.VirtualViews, 2.0.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package IL.VirtualViews@2.0.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=IL.VirtualViews&version=2.0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=IL.VirtualViews&version=2.0.0.1
                    
Install as a Cake Tool

IL.VirtualViews

Library which allows virtually register *.cshtml file as .cs classes with special attributes.

Targets .NET 10 and .NET 11, with matching ASP.NET Core Razor runtime compilation dependencies. The source generator remains on netstandard2.0 and Roslyn 5.0 APIs for .NET 10 SDK compiler-host compatibility.

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 static 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:

using IL.VirtualViews.Interfaces;

namespace VirtualViews;

public partial class Test : IVirtualView
{
    public static string ViewContent =>
    """
    @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.

External folders and compilation

Link .virtual.cshtml templates from another solution folder as Additional Files:

<AdditionalFiles Include="../SharedTemplates/Report.virtual.cshtml" />

Use a matching partial class in the generated namespace and apply VirtualViewPath to select its virtual Razor location. The source generator normalizes linked paths containing .. before deriving the namespace.

Template text is embedded in the generated assembly. Razor compiles each view on first use and reuses its normal compilation cache on subsequent requests. This is the existing behavior in both Debug and Release, not build-time Razor precompilation or eager startup compilation. No extra compiler cache is needed.

Debugging virtual views

By default, debug physical files are controlled by configuration key VirtualViews:Debug (true/false). When enabled, virtual view content is mirrored to temporary physical files and exposed through IFileInfo.PhysicalPath. This improves Razor diagnostics and makes virtual views easier to debug.

Example configuration:

{
  "VirtualViews": {
    "Debug": true
  }
}

You can still explicitly override this behavior in code:

services.AddVirtualViewsCapabilities(
    options => options.EnableDebugPhysicalFiles = true,
    "*"
);

or

builder.AddVirtualViewsCapabilities(
    options => options.EnableDebugPhysicalFiles = true,
    "*"
);
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on IL.VirtualViews:

Package Downloads
IL.RulesBasedOutputCache

Rules based output cache.

IL.AttributeBasedDI.Visualizer

Extension for IL.AttributeBasedDI

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.0.1 0 11/18/2026
2.0.0.1 0 11/18/2026
1.9.2.4 195 8/17/2026
1.9.2.3 779 5/4/2026
1.9.2.2 167 5/4/2026
1.9.2.1 232 5/3/2026
1.9.1.1 262 3/20/2026
1.9.0.3 226 1/21/2026
1.9.0.2 611 1/5/2026
1.9.0.1 150 1/5/2026
1.8.0 644 10/30/2025
1.7.0 1,910 4/8/2025
1.6.1 1,898 12/1/2024
1.6.0 197 12/1/2024
1.5.0 721 9/15/2024
1.4.0 261 9/13/2024 1.4.0 is deprecated because it has critical bugs.
1.3.2 233 9/13/2024
1.3.1 230 9/11/2024
1.3.0 246 8/10/2024
1.2.1 470 7/15/2024
Loading failed