How to prebuild C# generics before runtime

vb 276 Reputation points


Currently, C# generics are built at runtime. First time, generics execution is very slow because runtime compilation.

How to avoid runtime to get target x64 or x86 binaries where generics are already compiled to native binary.

Is there LINK option for that I am missing?

Thanks in advance!

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,684 questions
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
324 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,370 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,130 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,477 questions
0 comments No comments
{count} votes

Accepted answer
  1. Alberto Poblacion 1,556 Reputation points

    If I understand correctly, you want to bypass the JIT-compiler (Just In Time). For classical .Net Framework, you have a tool called NGEN.EXE (Native Image GENerator), which can take your IL files and turn them into executable binaries. Note that this is unrelated to whether you use Generics or not; the JIT and NGEN apply to any code with or without Generics.

    Link to documentation.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. vb 276 Reputation points

    So, you want to say there is no LINK/BUILD option in Visual Studio that can build native image?

    Only NGEN.exe that you must call from script or manually from cmd?