我正在尝试使用 Microsoft 的 CrossGen 实用程序作为 described here 将 .NET Core 5 库预编译为本地镜像。以改善启动时间。
但是 Getting CrossGen 的说明含糊不清:
If you install CoreCLR using a NuGet package, you can find CrossGen in the tools folder of the NuGet package.
如何通过 NuGet 安装 CrossGen?
到目前为止我尝试过的:
deleteme.csproj
的构建脚本到磁盘并有 <PackageReference Include="Microsoft.NETCore.App.Runtime.win-x64" Version="3.1.6" />
dotnet restore deleteme.csproj
.这会将 Crossgen nuget 包下载到本地缓存。~/.nuget/packages/microsoft.netcore.app.runtime.win-x64\3.1.6\tools\crossgen.exe
注意:我知道我可以使用 ReadyToRun 独立部署可执行文件的功能(如 described here)但是我需要优化类库,所以 ReadyToRun 不起作用。
问题
Internal implementation package not meant for direct consumption. Please do not reference directly. 2. 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.
在 ci/cd 构建期间,是否有正确的方法来预先 jit .NET Core 5 库?
最佳答案
如果您还没有找到这个问题的解决方案,首先,crossgen 现在有一个名为 crossgen2 的新工具,为了获得 crossgen2,您可以构建它,因为它是开源的,或者只是下载并解压缩它,因为所有 nuget 文件都是 zip文件。 crossgen 是 MSBuild 的一个内部工具,所以如果你想单独使用它,你必须使用命令行,幸运的是,crossgen 有一个内置的帮助页面,所以你希望知道你想要做什么。顺便说一句,你为什么不直接使用 R2R? R2R 包含 IL 和 AOT,您的应用程序使用 R2R 进行了优化,缺点正如 Tomas 在此处所说:https://devblogs.microsoft.com/dotnet/conversation-about-ready-to-run/
Tomas: The version resiliency concept and automatic switch-over to runtime JIT upon a mismatch also mean that a given R2R app can silently experience a perf degradation that may be hard to understand for an end-user.
我假设您不想使用 R2R,因为它包含 IL 和 AOT native 图像。在这种情况下,结合 Trim、压缩的单个文件,一个空白的 dotnet 独立程序会从 70 MB 减少到 20 MB。
关于c# - 如何在 ci/cd 中安装 CrossGen 以优化 .NET Core 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64363400/