Home > Software design >  Can DocumentationFile and GenerateDocumentationFile be used together in .Net project file?
Can DocumentationFile and GenerateDocumentationFile be used together in .Net project file?

Time:11-23

I'm writing a small analyzer for C# projects that checks if the XML documentation generation is present and set up correctly. There are two options for to specify XML documentation:

  • An older DocumentationFile option
  • A newer GenerateDocumentationFile flag. If the flag is set to true MSBuild should generate a XML documentation file with the project's name in the project's output directory.

Can both of these options be specified explicitly in the project file? Will the values from these options be combined or one of the options will be ignored?

CodePudding user response:

They both don't need to be set. If DocumentationFile is not empty, then GenerateDocumentationFile will set to true in an MSBuild target.

If you set GenerateDocumentationFile to true, then a default value for DocumentationFile will be set based on the project file name.

Relevant MSBuild targets

  <!-- Handle XML documentation file settings -->
  <PropertyGroup Condition="'$(GenerateDocumentationFile)' == ''">
    <GenerateDocumentationFile Condition="'$(DocumentationFile)' == ''">false</GenerateDocumentationFile>
    <GenerateDocumentationFile Condition="'$(DocumentationFile)' != ''">true</GenerateDocumentationFile>
  </PropertyGroup>

  <PropertyGroup Condition="'$(GenerateDocumentationFile)' == 'true' and '$(DocumentationFile)' == ''">
    <DocumentationFile Condition="'$(MSBuildProjectExtension)' == '.vbproj'">$(AssemblyName).xml</DocumentationFile>
    <DocumentationFile Condition="'$(MSBuildProjectExtension)' != '.vbproj'">$(IntermediateOutputPath)$(AssemblyName).xml</DocumentationFile>
  </PropertyGroup>

  <PropertyGroup Condition="'$(GenerateDocumentationFile)' != 'true'">
    <DocumentationFile />
  </PropertyGroup>
  • Related