简体   繁体   English

Dotnet Core - 如何在我编译的应用程序中链接包(dll)

[英]Dotnet Core - how are packages (dll's) linked in my compiled application

I am creating a new dotnet core ASP Web API (dotnet core 2.2) and one thing I noticed is that it has a reference to a package called Microsoft.AspNetCore.App .我正在创建一个新的 dotnet core ASP Web API(dotnet core 2.2),我注意到的一件事是它引用了一个名为Microsoft.AspNetCore.App的包。

When I look inside this package, it's really a reference to a bunch of other packages that Microsoft have defaulted in order for you to built all singing and all dancing Web applications.当我查看这个包的内部时,它实际上是对微软默认的一堆其他包的引用,以便您构建所有唱歌和所有跳舞的 Web 应用程序。

One thing I've noticed inside this are references to packages (for example) such as authentication or entity framework.我在其中注意到的一件事是对包的引用(例如),例如身份验证或实体框架。 None of which I need (I have a very very simple API).我不需要这些(我有一个非常简单的 API)。

My question我的问题

Does having references to unused packages effect overall compiled output of the application?引用未使用的包是否会影响应用程序的整体编译输出? Does it save on memory consumption (objects will not be instantiated if the dll is no longer linked).它是否节省了内存消耗(如果 dll 不再链接,则不会实例化对象)。

I imagine having references to packages that aren't being used still have a "footprint" (overall compiled size output) on your application, with links to the packages being setup and objects within the packages being instantiated (I could be completely wrong about this - so any clarification would be great!).我想对未使用的包的引用仍然在您的应用程序上有一个“足迹”(整体编译大小输出),链接到正在设置的包和正在实例化的包中的对象(我可能完全错了) - 所以任何澄清都会很棒!)。

I've used a concept of tree shaking in a UI world with the likes of WebPack.我在 WebPack 之类的 UI 世界中使用了摇树的概念。 I've seen this post which looks like dotnet has something similar :我看过这篇文章,看起来像 dotnet 有类似的东西:

https://ianqvist.blogspot.com/2018/01/reducing-size-of-self-contained-net.html https://ianqvist.blogspot.com/2018/01/reducing-size-of-self-contained-net.html

Thanks in advance for any advice!提前感谢您的任何建议!

I assume what you are looking for is a Tree Trimming feature which became a part of .Net Core 3.0 lately.我假设您正在寻找的是最近成为 .Net Core 3.0 的一部分的 Tree Trimming 功能。 It can be enabled through PublishTrimmed option in *.csproj file.它可以通过 *.csproj 文件中的PublishTrimmed选项启用。

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <PublishTrimmed>true</PublishTrimmed>
  </PropertyGroup>
</Project>

Here is a blog post from Scott Hanselman regarding the minifying the compiled artifacts.这是 Scott Hanselman 的一篇关于缩小编译工件的博客文章

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行命令“ dotnet project.dll”时,如何在.net core 1.1中获取正确的应用程序路径? - How to get the right application path in .net core 1.1 when run command “dotnet project.dll”? 如何检查我的 .NET Core 控制台应用程序是作为独立应用程序运行(通过运行 myapp.exe)还是使用 dotnet myapp.dll 运行? - How to check if my .NET Core console app is running as a self-contained app (by running myapp.exe) or if it's running using dotnet myapp.dll? 如何将 dotnet core System.Random 的实现替换为我所有应用程序的随机类? - How can I replace dotnet core System.Random in implementation with my random class for all my application? 如何在 dotnet core 中引用外部 dll 和 xml 注释 - How to reference external dll and xml comments in dotnet core 如何将使用dotnet-core构建的DLL与Python集成 - How to integrate a DLL built using dotnet-core with Python 如何从 .net 核心项目运行“do.net myDll.dll”? - How to run "dotnet myDll.dll" from a .net core project? 如何查看我的应用程序加载了哪些dll? - How can I see which dll's are loaded by my application? 如何在C#编译的应用程序中嵌入DLL - How to embed a DLL within a C# compiled application 如何重写已编译的Web应用程序.net dll中的类 - how to override a class in a compiled web application .net dll Dollnet核心的DllImport返回当前DLL的DLLNotFoundException - DllImport for Dotnet core returning DLLNotFoundException for present DLL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM