简体   繁体   English

C# Visual Studio:在程序集中嵌入 XML 文档文件

[英]C# Visual Studio: Embed XML Documentation File in Assembly

I am hoping to add the auto-generated XML documentation file produced by Visual Studio to my project's Assembly as an Embedded Resource, but I am uncertain how to go about this.我希望将 Visual Studio 生成的自动生成的 XML 文档文件作为嵌入式资源添加到我的项目的程序集中,但我不确定如何 go 解决这个问题。 I am aware that I can manually alter the .csproj file to add resources, using something like:我知道我可以手动更改.csproj文件以添加资源,使用类似:

<EmbeddedResource Include="Path\To\File\MyEmbeddedResource.meta.xml">
    <Link>MyEmbeddedResource.meta.xml</Link>
</EmbeddedResource>

But I don't know how that interacts with the Build procedure, or what path I would provide for the XML file, given that it itself is placed in the build folder?但我不知道它如何与构建过程交互,或者我将为 XML 文件提供什么路径,因为它本身位于构建文件夹中?

I know I can use the above snippet to add an arbitrary file as an embedded resource for the .dll , but how do I ensure that the documentation file is up to date, and uses the one generated in the most recent build?我知道我可以使用上面的代码片段将任意文件添加为.dll的嵌入式资源,但是如何确保文档文件是最新的,并使用最新版本中生成的文件?

The overall goal here is to have the documentation accessible via reflection, such that the .dll has fewer external file dependencies.这里的总体目标是通过反射访问文档,这样.dll具有较少的外部文件依赖性。 Given that the project itself is a Class Library, I would hope that any answer doesn't break when the Assembly is included in another project.鉴于该项目本身是一个 Class 库,我希望当该程序集包含在另一个项目中时,任何答案都不会中断。

The embedded resource file is not placed in the build output folder, it is included in the binary output of the DLL file.嵌入的资源文件没有放在 build output 文件夹中,它包含在 DLL 文件的二进制 output 中。 Like you would define a public constant string whose content is the XML file's content.就像您将定义一个公共常量字符串,其内容是 XML 文件的内容。 But embedded resources can be accessed via solution of https://stackoverflow.com/a/3314213/593045但是可以通过https的解决方案访问嵌入式资源://stackoverflow.com/a/3314213/593045

The resouceName depends in which subfolders you place the XML file and how you call it - that defines the resource name. resouceName 取决于您将 XML 文件放置在哪些子文件夹中以及如何调用它 - 这定义了资源名称。 So I would use a base folder eg "embeddedXmlDoc" and inside that an identical structure of folders (a folder for each text between. in namespaces) like the classes and its namespaces you want to document.因此,我将使用一个基本文件夹,例如“embeddedXmlDoc”,并在其中使用相同的文件夹结构(命名空间中的每个文本的文件夹),如您要记录的类及其命名空间。 Then you could find the right file just by using their namespace and class name.然后,您只需使用它们的命名空间和 class 名称即可找到正确的文件。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM