How to generate XML documentation for CSPROJ with multiple targets

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 11:27:12

问题


I have a library project that has multiple targets, e.g. in the CSPROJ file it has:

<TargetFrameworks>net40;net46;net461;net462;net47</TargetFrameworks>

If I want XML documentation for all combinations of these target frameworks and Debug and Release configurations I have to select each one in turn in the UI using the Build Configuration Manager and then set it to build XML documentation for that combination and each combination is then listed separately as a PropertyGroup in the CSPROJ with the intended output file for the XML documentation.

Is there a better way?

Posting question and answer because I didn't find this documented anywhere else online


回答1:


An easy way is to set the GenerateDocumentationFile property to true. The VS UI want to set the path, the MSBuild targets will set this property to true if the path is set or set a default path if the GenerateDocumentationFile property is true. So you can add this to your csproj file:

<PropertyGroup>
  <GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

If you want to set this to true for all your projects to share it, create a file named Directory.Build.props in your solution's directory with the following content and it will be auto-imported into any projects in the directory hierarchy below:

<Project>
  <PropertyGroup>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
  </PropertyGroup>
</Project>



回答2:


One way to fix this is to include the following in each CSPROJ file:

<!-- Build XML documentation for all combinations of target framework x configuration -->
<PropertyGroup>
 <DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml 
 </DocumentationFile>
</PropertyGroup>

An even better way is to link to a shared configuration file:

<!-- This must come after any other configuration so that it overwrites it -->
<Import Project="$(MSBuildThisFileDirectory)..\Shared.msbuild" />

... and then place the above lines in that shared configuration file where you can also set all the other solution-wide CSPROJ settings like Product, Company, Copyright, ...



来源:https://stackoverflow.com/questions/47115877/how-to-generate-xml-documentation-for-csproj-with-multiple-targets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!