Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET core build output contains a lot of DLL files

I have .NET Core solution with ~30 projects, and I don't get one thing - each project compiled Bin output is very huge. Basically it contains whole bunch of Microsoft.AspNetcore.* and System.* assemblies, which makes output about 15-30mb (even for really small projects). The solution divided into smaller projects with purpose to make it less coupled, but now it makes more troubles than it helps - overall size of all compiled projects is around 700mb..

I agree that it would be OK for "startup"/"composite root" projects, where everything should be in one place, but now it looks like every project is "published", or like compiled as "standalone" and not using installed frameworks.

It's not a problem as such, but it makes the solution not so robust in terms of CI/CD, publishing artifacts, etc. Any ideas what might be wrong? Is it really as designed?

One possible reason is that for some historical reason my solution targets net461 (aka "full" .NET Framework). However I'm considering porting everything to netcoreapp1.x/netstandard. I tried to do it with some projects - and it looked like for "library" projects it copies only few assemblies, but for some other projects (e.g. tests written with xUnit) - there are still a lot of "framework-based" DLLs, that could be used from global cache or smth.. Even in net461 current situation is still a bit weird.

I also was trying to put all built artifacts into one folder on CI server, but there are other issues with it - like third-party libraries conflicts, when different version libraries in different projects are used. It's understandable for third-party libraries, but "framework" libraries could be "smarter"..

Just for reference, full list of assemblies being copied to Bin output:

Autofac.dll
Autofac.Extensions.DependencyInjection.dll
AutoMapper.dll
FluentAssertions.Core.dll
FluentAssertions.dll
JetBrains.Annotations.dll
Microsoft.AspNetCore.Antiforgery.dll
Microsoft.AspNetCore.Authorization.dll
Microsoft.AspNetCore.Cors.dll
Microsoft.AspNetCore.Cryptography.Internal.dll
Microsoft.AspNetCore.DataProtection.Abstractions.dll
Microsoft.AspNetCore.DataProtection.dll
Microsoft.AspNetCore.Diagnostics.Abstractions.dll
Microsoft.AspNetCore.Diagnostics.dll
Microsoft.AspNetCore.Hosting.Abstractions.dll
Microsoft.AspNetCore.Hosting.dll
Microsoft.AspNetCore.Hosting.Server.Abstractions.dll
Microsoft.AspNetCore.Html.Abstractions.dll
Microsoft.AspNetCore.Http.Abstractions.dll
Microsoft.AspNetCore.Http.dll
Microsoft.AspNetCore.Http.Extensions.dll
Microsoft.AspNetCore.Http.Features.dll
Microsoft.AspNetCore.HttpOverrides.dll
Microsoft.AspNetCore.JsonPatch.dll
Microsoft.AspNetCore.Localization.dll
Microsoft.AspNetCore.Mvc.Abstractions.dll
Microsoft.AspNetCore.Mvc.ApiExplorer.dll
Microsoft.AspNetCore.Mvc.Core.dll
Microsoft.AspNetCore.Mvc.Cors.dll
Microsoft.AspNetCore.Mvc.DataAnnotations.dll
Microsoft.AspNetCore.Mvc.dll
Microsoft.AspNetCore.Mvc.Formatters.Json.dll
Microsoft.AspNetCore.Mvc.Localization.dll
Microsoft.AspNetCore.Mvc.Razor.dll
Microsoft.AspNetCore.Mvc.Razor.Host.dll
Microsoft.AspNetCore.Mvc.TagHelpers.dll
Microsoft.AspNetCore.Mvc.Versioning.dll
Microsoft.AspNetCore.Mvc.ViewFeatures.dll
Microsoft.AspNetCore.Razor.dll
Microsoft.AspNetCore.Razor.Runtime.dll
Microsoft.AspNetCore.ResponseCaching.Abstractions.dll
Microsoft.AspNetCore.Routing.Abstractions.dll
Microsoft.AspNetCore.Routing.dll
Microsoft.AspNetCore.Server.IISIntegration.dll
Microsoft.AspNetCore.Server.Kestrel.dll
Microsoft.AspNetCore.WebUtilities.dll
Microsoft.CodeAnalysis.CSharp.dll
Microsoft.CodeAnalysis.dll
Microsoft.DotNet.PlatformAbstractions.dll
Microsoft.Extensions.Caching.Abstractions.dll
Microsoft.Extensions.Caching.Memory.dll
Microsoft.Extensions.Configuration.Abstractions.dll
Microsoft.Extensions.Configuration.Binder.dll
Microsoft.Extensions.Configuration.dll
Microsoft.Extensions.Configuration.EnvironmentVariables.dll
Microsoft.Extensions.Configuration.FileExtensions.dll
Microsoft.Extensions.Configuration.Json.dll
Microsoft.Extensions.DependencyInjection.Abstractions.dll
Microsoft.Extensions.DependencyInjection.dll
Microsoft.Extensions.DependencyModel.dll
Microsoft.Extensions.FileProviders.Abstractions.dll
Microsoft.Extensions.FileProviders.Composite.dll
Microsoft.Extensions.FileProviders.Physical.dll
Microsoft.Extensions.FileSystemGlobbing.dll
Microsoft.Extensions.Globalization.CultureInfoCache.dll
Microsoft.Extensions.Localization.Abstractions.dll
Microsoft.Extensions.Localization.dll
Microsoft.Extensions.Logging.Abstractions.dll
Microsoft.Extensions.Logging.Console.dll
Microsoft.Extensions.Logging.dll
Microsoft.Extensions.ObjectPool.dll
Microsoft.Extensions.Options.ConfigurationExtensions.dll
Microsoft.Extensions.Options.dll
Microsoft.Extensions.PlatformAbstractions.dll
Microsoft.Extensions.Primitives.dll
Microsoft.Extensions.WebEncoders.dll
Microsoft.Net.Http.Headers.dll
Microsoft.Win32.Primitives.dll
Newtonsoft.Json.dll
NLog.dll
NLog.Extensions.Logging.dll
NLog.Web.AspNetCore.dll
System.AppContext.dll
System.Buffers.dll
System.Collections.Immutable.dll
System.ComponentModel.Annotations.dll
System.ComponentModel.Primitives.dll
System.ComponentModel.TypeConverter.dll
System.Console.dll
System.Diagnostics.DiagnosticSource.dll
System.Diagnostics.FileVersionInfo.dll
System.Diagnostics.StackTrace.dll
System.Globalization.Calendars.dll
System.IO.Compression.dll
System.IO.FileSystem.dll
System.IO.FileSystem.Primitives.dll
System.Net.Http.dll
System.Net.Sockets.dll
System.Numerics.Vectors.dll
System.Reflection.Metadata.dll
System.Runtime.CompilerServices.Unsafe.dll
System.Runtime.InteropServices.RuntimeInformation.dll
System.Security.Cryptography.Algorithms.dll
System.Security.Cryptography.Encoding.dll
System.Security.Cryptography.Primitives.dll
System.Security.Cryptography.X509Certificates.dll
System.Text.Encoding.CodePages.dll
System.Text.Encodings.Web.dll
System.Threading.Tasks.Extensions.dll
System.Threading.Thread.dll
System.ValueTuple.dll
System.Xml.ReaderWriter.dll
System.Xml.XmlDocument.dll
System.Xml.XPath.dll
System.Xml.XPath.XDocument.dll
like image 717
Aleksanderis Avatar asked Sep 02 '25 02:09

Aleksanderis


1 Answers

It seems I found it myself.. There are CopyLocalLockFileAssemblies and CopyNuGetImplementations flags for .NET Core projects (i.e. new-style *.csproj files).

For .NET Core it's:

<!-- dependencies coming from the package manager lock file should not be copied locally for .NET Core and .NETStandard projects -->
<CopyLocalLockFileAssemblies Condition="'$(CopyLocalLockFileAssemblies)' == ''">false</CopyLocalLockFileAssemblies>

For .NET Framework it's set as "true" by some reason. Therefore binaries are so big in size.

Regarding xUnit projects - they are also overriding these flags and set them to true. Actually tests are working with having them "false" when you are using dotnet xunit or dotnet test, but it should be really "true" if you want to use xUnit console runner.

It doesn't really help me, but at least it explains why it happens.. It's really frustrating to have project just with one class, which is ~5kb, but Binary output is 16Mb.

like image 69
Aleksanderis Avatar answered Sep 05 '25 00:09

Aleksanderis