I want to build documentation xml files for my C# projects. How can I do that?
This is my CommonBase.props
file, imported by about a hundred csproj
files. The point of it is to save editing the same information in different places.
I want to build the documentation to the OutputPath below.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Common properties for projects. This project can't be built by itself, but is imported by several projects. Be careful to prepend $(MSBuildThisFileDirectory) before any paths relative to this file.
If you import this project from a csproj file, you should still define at least ProjectGuid, AssemblyName, RootNamespace and OutputType in the csproj.
-->
<PropertyGroup>
<!-- If configuration not specified, default to debug. If platform not specified, default to x64. Necessary for London continuous integration server. -->
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x64</Platform>
<PlatformTarget>$(Platform)</PlatformTarget>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<AppDesignerFolder>Properties</AppDesignerFolder>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<DebugSymbols>true</DebugSymbols>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)' == 'x86'">
<OutputPath>$(MSBuildThisFileDirectory)..\..\bin32\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)' == 'x64'">
<OutputPath>$(MSBuildThisFileDirectory)..\..\bin\</OutputPath>
</PropertyGroup>
</Project>
This is what a csproj looks like
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Import Project="..\Build\CommonBase.props" />
The C# compiler produces an XML file that contains structured data representing the comments and the API signatures. Other tools can process that XML output to create human-readable documentation in the form of web pages or PDF files, for example.
To insert XML comments for a code element Type /// in C#, or ''' in Visual Basic.
C# XmlDocument tutorial shows how to work with XML in C# with XmlDocument. Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. XML is often used for application configuration, data storage and exchange.
The cref attribute in an XML documentation tag means "code reference." It specifies that the inner text of the tag is a code element, such as a type, method, or property.
You need to add the following line to the csproject files: <DocumentationFile>bin\Debug\ProjectName.XML</DocumentationFile>
(under PropertyGroup)
In the Project Properties you can manually put this in the Build tab with the "XML Documentation File" checkbox.
Or with code to change many project files at once:
var projectFiles = System.IO.Directory.GetFiles(
@"C:\somePath", "*.csproj", SearchOption.AllDirectories);
foreach (var file in projectFiles)
{
var xmlFile = XDocument.Load(file);
var propNode = xmlFile.Root.Elements().First();
var assemblyName = propNode.Elements().First(x =>x.Name.LocalName == "AssemblyName").Value;
propNode.Add(new XElement("DocumentationFile", string.Format("somePlace\\{0}.XML", assemblyName)));
xmlFile.Save(file);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With