How to install/use CrossGen to optimize .NET Core Library as part of ci/cd?
See original GitHub issueI am attempting to pre-jit/Ahead-Of-Time (AOT) compile a .NET Core 5 Library to a Native Image using the CrossGen utility as described here to improve start up time.
However the instructions for Getting CrossGen are vague:
If you install CoreCLR using a NuGet package, you can find CrossGen in the tools folder of the NuGet package.
How do I install CrossGen via NuGet?
What I’ve tried so far:
-
Create a build script that writes
deleteme.csproj
to disk and has a<PackageReference Include="Microsoft.NETCore.App.Runtime.win-x64" Version="3.1.6" />
-
Run
dotnet restore deleteme.csproj
. This will download the Crossgen nuget package to local cache. -
I can now run
~/.nuget/packages/microsoft.netcore.app.runtime.win-x64\3.1.6\tools\crossgen.exe
NOTE: I know I can use the ReadyToRun feature for Self-Contained Deployment executable (as described here) HOWEVER I need to optimize a Class Library, so ReadyToRun doesn’t work.
Problem
Internal implementation package not meant for direct consumption. Please do not reference directly.
- Installation like this seems incorrect. I’d expect CrossGen to be installed as a dotnet tool rather than needing to create a dummy project and run
dotnet restore
in order to download a copy of a nuget package in cache.
Is there a correct way to pre-jit a .NET Core 5 Library during a ci/cd build?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
R2R should work on libraries, for context all the .net libraries are crossgened themselves. Note that if R2R code is determined to be invalid for the platform, then the runtime should fall back to JITing. In .net 6 with crossgen2 we will also support a composite mode where apps can we published with all app+library code included in a single composite image.
<PublishReadyToRun>true</PublishReadyToRun>
does work for libraries when targetingnetcoreapp3.1
,net5.0
, and the upcomingnet6.0
framework. If you run the following commands in an empty directory:you will see the
crossgen.exe
command line. Ther2rdump.exe
utility can be used to see generated native code placed into the managed DLL.