Skip to content

Use Precompiled Views for Razor #180

Answered by bdukes
bdukes asked this question in Q&A
Nov 28, 2022 · 2 comments · 4 replies
Discussion options

You must be logged in to vote

I was able to track down how the Razor Compiler looks for pre-compiled views and to feed it our assembly so that it never tried to use any view files in the file system. After calling services.AddRazor(), I call this method, passing in a type from the type that has the views (since this is .NET 3.1 it generates a sidecar assembly with .Views added to the name; in .NET 6, these get added directly to the main assembly, so that piece won't be needed going forward).

    private static IServiceCollection AddCompiledRazorAssembly(IServiceCollection serviceCollection, Type assemblyType)
    {
        if (serviceCollection == null)
        {
            throw new ArgumentNullException(nameof(serv…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@daveaglick
Comment options

@bdukes
Comment options

@bdukes
Comment options

@daveaglick
Comment options

Answer selected by daveaglick
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants