question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to install/use CrossGen to optimize .NET Core Library as part of ci/cd?

See original GitHub issue

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

  1. 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" />

  2. Run dotnet restore deleteme.csproj. This will download the Crossgen nuget package to local cache.

  3. 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

  1. The Nuget package has a big warning:

Internal implementation package not meant for direct consumption. Please do not reference directly.

  1. 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
mangod9commented, Dec 22, 2020

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.

0reactions
AntonLapounovcommented, Apr 19, 2021

<PublishReadyToRun>true</PublishReadyToRun> does work for libraries when targeting netcoreapp3.1, net5.0, and the upcoming net6.0 framework. If you run the following commands in an empty directory:

dotnet new classlib
dotnet publish -p:PublishReadyToRun=True -c Release -r win-x64 -v:n

you will see the crossgen.exe command line. The r2rdump.exe utility can be used to see generated native code placed into the managed DLL.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to install CrossGen to optimize .NET Core Library in ci ...
Run dotnet restore deleteme.csproj . This will download the Crossgen nuget package to local cache. I can now run ~/.nuget/packages/microsoft.
Read more >
Use the .NET SDK in Continuous Integration (CI) ...
NET SDK in your workflow. The recommended way to install the .NET SDK in a workflow is with the actions/setup-net-core-sdk action.
Read more >
Crossgen as build step with .NET Core 3.0 - CodeTherapist
NET application can run, it requires a JIT (Just-in-Time) compiler that translates the IL-Code into native code (that is platform- and processor ...
Read more >
Creating a CI/CD pipeline for a .NET library: Part 1 - Intro
Setting up a complete CI/CD pipeline for a .NET library, from building and testing in different platforms, visualizing code coverage and ...
Read more >
Untitled
NET Core Crossgen2 compilation without IL code - Stack Overflow dimensione wifi ... NET Core Library in ci/cd How to install/use CrossGen to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found