简体   繁体   中英

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. I am aware that I can manually alter the .csproj file to add resources, using something like:

<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?

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?

The overall goal here is to have the documentation accessible via reflection, such that the .dll has fewer external file dependencies. 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.

The embedded resource file is not placed in the build output folder, it is included in the binary output of the DLL file. Like you would define a public constant string whose content is the XML file's content. But embedded resources can be accessed via solution of 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. 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. Then you could find the right file just by using their namespace and class name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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