c# - 如何只发布需要的依赖?

标签 c# .net .net-core

如果我在 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”依赖项的一部分。我如何才能将其缩减为应用程序实际使用的内容?

最佳答案

根据 deployment documentation :

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/

相关文章:

c# - 为什么 MSDN 站点上的这个 lambda 示例不起作用?

c# - Web 浏览器中的内容在 Windows 窗体应用程序中自动缩放时出现问题

c# - 没有映射到数据操作中使用的列 'CleaningEmployees.Id' 的属性

.net-core - 在 Ubuntu 中独立部署 .NET Core 应用程序

c# - 验证过程中如何清理 SimpleInjector 创建的实例?

c# - 嵌套异步/等待方法

c# - 从动态类型中获取有用的调试信息

c# - 从 C++ 调用 C# 事件

c# - 从另一个 C# 程序捕获 c# 可执行输出

.net - IronPython无法导入模块 "os"