我创建了一个.net标准2.0库
我添加了对log4net的引用
我运行以下内容:
dotnet publish --output d:\temp\publishout
我的问题是为什么我在发布文件夹中看到所有这些输出?
我希望像System.Linq是已经安装在机器上的完整.net框架和.net核心2.0运行时的一部分
Directory: D:\temp\publishout
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 13/01/2018 20:32 runtimes
-a---- 13/01/2018 20:32 56477 ClassLibraryStandard.deps.json
-a---- 13/01/2018 20:32 4096 ClassLibraryStandard.dll
-a---- 13/01/2018 20:32 244 ClassLibraryStandard.pdb
-a---- 08/03/2017 19:26 221184 log4net.dll
-a---- 11/06/2016 23:13 21856 System.AppContext.dll
-a---- 11/06/2016 23:13 93432 System.Collections.Concurrent.dll
-a---- 21/12/2017 17:58 180984 System.Collections.Immutable.dll
-a---- 21/12/2017 17:58 88472 System.Collections.NonGeneric.dll
-a---- 11/06/2016 23:13 34224 System.Diagnostics.DiagnosticSource.dll
-a---- 11/06/2016 23:13 27544 System.Diagnostics.StackTrace.dll
-a---- 11/06/2016 23:13 22432 System.IO.FileSystem.Primitives.dll
-a---- 11/06/2016 23:14 127304 System.Linq.dll
-a---- 11/06/2016 23:14 32504 System.Net.WebHeaderCollection.dll
-a---- 21/12/2017 17:58 428784 System.Reflection.Metadata.dll
-a---- 21/12/2017 17:58 29608 System.Reflection.TypeExtensions.dll
-a---- 11/06/2016 23:14 71392 System.Runtime.Numerics.dll
-a---- 21/12/2017 17:58 31168 System.Runtime.Serialization.Formatters.dll
-a---- 21/12/2017 17:58 29632 System.Runtime.Serialization.Primitives.dll
-a---- 11/06/2016 23:14 57720 System.Security.Claims.dll
-a---- 21/12/2017 17:58 23472 System.Security.Cryptography.OpenSsl.dll
-a---- 11/06/2016 23:14 45504 System.Security.Cryptography.Primitives.dll
-a---- 21/12/2017 17:58 21736 System.Security.Principal.dll
-a---- 11/06/2016 23:14 114080 System.Text.RegularExpressions.dll
-a---- 11/06/2016 23:15 50016 System.Threading.dll
-a---- 21/12/2017 17:58 24328 System.Threading.Tasks.Extensions.dll
-a---- 11/06/2016 23:14 22400 System.Threading.Thread.dll
-a---- 11/06/2016 23:14 22416 System.Threading.ThreadPool.dll
-a---- 11/06/2016 23:15 606432 System.Xml.ReaderWriter.dll
-a---- 21/12/2017 17:58 138104 System.Xml.XmlDocument.dll
答案 0 :(得分:0)
这是因为在.NET Standard 2.0之前,某些实现在各个包中作为程序集提供,并且.NET Core的构建输出将其排除,因为这些包是Microsoft.NETCore.App
元数据包的一部分。
对于.NET Standard 2.0,不再使用许多软件包,NETStandard.Library
版本2.0.0包含编译所需的所有参考程序集。
这里的问题是某些软件包是为“.NET Standard 1. *”构建的,但现在“在.NET Standard 2.0中”。
例如,NETStandard 1.6应用程序必须手动添加System.Data.Common
以使用包含的类型。 NETStandard.Library
版本2.0.0已包含类型,不需要此软件包。
发布.NET Core 2.0应用程序时,修剪逻辑会检测此包并将其删除。对于.NET标准项目,这不会发生,因为此处没有应用修剪逻辑,因此您最终会在发布输出中使用DLL。这是为了查看这是缺失的优化还是设计(opened a GitHub issue for it)。
但是,正如@Lex Li在评论中已经提到的那样,您几乎不需要.NET标准库的发布输出。使用项目引用或通过NuGet包共享项目。只有基于插件的体系结构才需要发布输出,目前解决方法是使插件目标与应用程序的目标框架相同(例如,创建.NET Core库而不是.NET Standard)。