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
.
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.
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).
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).
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. I've seen this post which looks like dotnet has something similar :
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.
It can be enabled through PublishTrimmed
option in *.csproj file.
<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.