简体   繁体   English

.NET 核心 - System.Private.CoreLib.dll 与 System.Runtime

[英].NET Core - System.Private.CoreLib.dll vs System.Runtime

In a .NET Core App, if I do在 .NET 核心应用程序中,如果我这样做

typeof(DateTime).Assembly.Location

I get我得到

C:\Program Files\do.net\shared\Microsoft.NETCore.App\3.1.4\System.Private.CoreLib.dll C:\Program Files\do.net\shared\Microsoft.NETCore.App\3.1.4\System.Private.CoreLib.dll

But the documentation for the DateTime struct says the assembly is System.Runtime.dll但是 DateTime 结构的文档说程序集是System.Runtime.dll

I am trying to locate the XML Documentation file for DateTime .我正在尝试找到DateTime的 XML 文档文件。 I cannot locate a System.Private.CoreLib.xml on my system but a System.Runtime.xml does accompany the System.Runtime.dll file in its folder (per XML documentation convention).我无法在我的系统上找到System.Private.CoreLib.xml ,但System.Runtime.xml确实伴随着System.Runtime.dll文件在其文件夹中(根据 XML 文档约定)。

How does System.Private.CoreLib.dll relate to System.Runtime.dll ? System.Private.CoreLib.dllSystem.Runtime.dll有何关系?

I am trying to use Roslyn to grab the XML <Summary> tag content, (similar to a hover tooltip in Visual Studio) but I cant see how to associate a Type with the location of the XML documentation?我正在尝试使用 Roslyn 获取 XML <Summary>标记内容(类似于 Visual Studio 中的 hover 工具提示),但我看不到如何将类型与 XML 文档的位置相关联?

System.Private.CoreLib.dll is the assembly that contains the core types of the .NET runtime, including the System namespace types such as DateTime. System.Private.CoreLib.dll 是包含 .NET 运行时核心类型的程序集,包括 DateTime 等 System 命名空间类型。 System.Runtime.dll is a separate assembly that contains types that are used by the runtime, but are not considered part of the core runtime itself. System.Runtime.dll 是一个单独的程序集,其中包含运行时使用的类型,但不被视为核心运行时本身的一部分。

The XML documentation for the DateTime struct is included in System.Private.CoreLib.xml, which is located in the same folder as System.Private.CoreLib.dll. DateTime 结构的 XML 文档包含在 System.Private.CoreLib.xml 中,它与 System.Private.CoreLib.dll 位于同一文件夹中。

To associate a Type with the location of its XML documentation, you can use the XmlDocCommentProvider class from the Microsoft.CodeAnalysis.CSharp.DocumentationComments namespace.要将类型与其 XML 文档的位置相关联,您可以使用 Microsoft.CodeAnalysis.CSharp.DocumentationComments 命名空间中的 XmlDocCommentProvider class。 Here is an example of how you can use it to retrieve the XML documentation for the DateTime struct:下面是一个示例,说明如何使用它来检索 DateTime 结构的 XML 文档:

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.DocumentationComments;

// ...

var type = typeof(DateTime);

var assembly = type.Assembly;

var xmlDocCommentProvider = XmlDocCommentProvider.Create(assembly);

var docComment = xmlDocCommentProvider.GetDocumentationComment(type);

// Extract the summary element from the XML documentation
var summaryElement = docComment.DescendantNodes().OfType<XmlElementSyntax>().FirstOrDefault(x => x.StartTag.Name.ToString() == "summary");

if (summaryElement != null)
{
    var summaryText = summaryElement.GetText().ToString();
}

Ever since the introduction of .NET Standard, System.Runtime is an important assembly that forwards types to the actual assemblies (like System.Private.CoreLib.dll ) with their defitions,自从引入 .NET 标准以来, System.Runtime是一个重要的程序集,它将类型及其定义转发到实际程序集(如System.Private.CoreLib.dll ),

https://learn.microsoft.com/en-us/do.net/standard/assembly/type-forwarding https://learn.microsoft.com/en-us/do.net/standard/assembly/type-forwarding

There are tons of similar questions like this .有很多类似的问题

To learn more, use a tool like ILSpy to decompile System.Runtime and locate the type forwarding statements.要了解更多信息,请使用 ILSpy 等工具反编译System.Runtime并找到类型转发语句。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#.NET Core如何在System.Private.CoreLib.dll中调试System.IO.FileNotFoundException? - C# .NET Core How to debug System.IO.FileNotFoundException in System.Private.CoreLib.dll? 抛出异常:System.Private.CoreLib.dll 中的“System.MissingMethodException” - Exception thrown: 'System.MissingMethodException' in System.Private.CoreLib.dll Windows 平台上的 .NET MAUI 应用程序在 System.Private.CoreLib.dll 中获取 System.IO.FileNotFoundException' - .NET MAUI app on Windows platform getting System.IO.FileNotFoundException' in System.Private.CoreLib.dll System.Private.CoreLib.dll中发生&#39;System.InvalidOperationException&#39;但未在用户代码中处理 - 'System.InvalidOperationException' occurred in System.Private.CoreLib.dll but was not handled in user code Blazor - 复制 Razor 页面导致 System.Private.CoreLib.dll 中出现错误“System.NullReferenceException” - Blazor - Copying Razor Page Causes Error 'System.NullReferenceException' in System.Private.CoreLib.dll 无法使用.Net Core dll加载文件或程序集&#39;System.Runtime&#39; - Could not load file or assembly 'System.Runtime' with .Net Core dll 抛出异常:Microsoft.VisualStudio.TestPlatform.Common.dll AND System.Private.CoreLib.dll 中的“System.IO.FileLoadException” - Exception thrown: 'System.IO.FileLoadException' in Microsoft.VisualStudio.TestPlatform.Common.dll AND System.Private.CoreLib.dll ASP.NET Core 2.0站点-FileIOException System.Runtime - ASP.NET Core 2.0 Site - FileIOException System.Runtime 如何查找System.Private.CoreLib.ni.dll中发生“ System.Runtime.InteropServices.SEHException”的原因? - How to find reason for 'System.Runtime.InteropServices.SEHException' occurred in System.Private.CoreLib.ni.dll? ASP.NET:由Nuget引起的.NET Framework /标准/核DLL冲突。 “你必须添加对程序集System.Runtime的引用......” - ASP.NET: .NET Framework/Standard/Core DLL collisions, caused by Nuget. “You must add a reference to assembly System.Runtime…”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM