如果我在 Visual Studio 2017 中创建一个“Hello World”.NET Core C# 控制台应用程序并运行
dotnet publish -c Release -r win10-x64 --self-contained
生成的 publish
文件夹中有 215 个文件,总计 62MB,包括应用程序未使用的整个 .NET。例如,它有 System.Security.Cryptography.OpenSsl.dll
。
这是我似乎无法手动编辑的“Microsoft.NETCore.App”依赖项的一部分。我如何才能将其缩减为应用程序实际使用的内容?
最佳答案
Unlike FDD, a self-contained deployment (SCD) doesn't rely on the presence of shared components on the target system. All components, including both the .NET Core libraries and the .NET Core runtime, are included with the application
(emphasis mine)
如果您不想将整个 .NET Core 运行时与您的应用程序一起部署,那么您应该使用 Framework-dependent Deployment (FDD) 而不是 Self-contained Deployment (SCD)。
dotnet publish -c Release
将来,CoreRT runtime – 在撰写本文时仍在开发中 – 旨在允许创建特定于运行时且不需要任何其他文件的单个预编译 native 可执行文件。
引用:Is there a way to make a console application run using only a single file in .NET Core?
关于c# - 如何只发布需要的依赖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49200503/