[英]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.