.NET核心构建输出包含许多DLL文件

时间:2017-08-03 11:35:55

标签: asp.net-core .net-core

我有大约30个项目的.NET Core解决方案,而且我没有得到一件事 - 每个项目编译的Bin输出都非常庞大。基本上它包含了一大堆Microsoft.AspNetcore。*和System。*程序集,它们的输出大约为15-30mb(即使是非常小的项目)。 该解决方案分为较小的项目,目的是减少它的耦合,但现在它造成的麻烦比它有所帮助 - 所有编译项目的总体规模大约为700mb ..

我同意" startup" /"复合root"项目,其中一切都应该在一个地方,但现在看起来每个项目都是"发布",或者像编译为"独立"而不使用已安装的框架。

这不是一个问题,但它使得解决方案在CI / CD,发布工件等方面不那么强大。任何想法可能是错的?这真的是设计的吗?

一个可能的原因是,由于某些历史原因,我的解决方案针对net461(又名"完整" .NET Framework)。但是我考虑将所有内容移植到netcoreapp1.x / netstandard。我尝试用一​​些项目来做这件事 - 它看起来像是"图书馆"它只复制几个程序集的项目,但对于其他一些项目(例如用xUnit编写的测试) - 仍然有很多基于框架的#34; DLL,可以从全局缓存或smth使用..即使在net461当前的情况仍然有点奇怪。

我还尝试将所有构建的工件放入CI服务器上的一个文件夹中,但是当使用不同项目中的不同版本库时,还存在其他问题 - 例如第三方库冲突。这对第三方图书馆来说是可以理解的,但"框架"图书馆可以更聪明" ..

仅供参考,复制到Bin输出的程序集的完整列表:

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

2 个答案:

答案 0 :(得分:2)

似乎我自己发现了.. .NET Core项目有CopyLocalLockFileAssembliesCopyNuGetImplementations标志(即新式* .csproj文件)。

对于.NET Core,它是:

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

对于.NET Framework,由于某种原因,它被设置为“true”。因此二进制文件的大小非常大。

关于xUnit项目 - 它们也会覆盖这些标志并将它们设置为true。实际上,当您使用dotnet xunitdotnet test时,测试正在使用它们“假”,但如果您想使用xUnit console runner,它应该是“真的”。

这对我没有帮助,但至少它解释了为什么会发生这种情况。 让项目只有一个类,大约是5kb,但二进制输出是16Mb,真的很令人沮丧。

答案 1 :(得分:2)

我遇到了一个类似于针对net461的.NET核心控制台应用程序的类似问题(这让我来到这里)。

Microsoft.Packaging.Tools.Trimming工具(现在找到here)最终为我完成了这项工作,因为大多数复制的程序集都没有被我的应用程序使用。只需安装nuget package并在项目文件中插入以下行:

<PropertyGroup>
   <TrimUnusedDependencies>true</TrimUnusedDependencies>
</PropertyGroup>

这将检查未使用的依赖项并将其删除。也许这可以减少DLL文件的数量。