如何为具有多个目标的CSPROJ生成XML文档

Ian*_*cer 17 c# msbuild xml-documentation

我有一个具有多个目标的库项目,例如它在CSPROJ文件中:

<TargetFrameworks>net40;net46;net461;net462;net47</TargetFrameworks>
Run Code Online (Sandbox Code Playgroud)

如果我想为这些目标框架和所有组合的XML文档DebugRelease配置,我使用生成配置管理器来选择每一个设置在用户界面,然后将其设置为建立该组合XML文档和每一个组合,然后单独作为上市a PropertyGroup在CSPROJ中,带有XML文档的预期输出文件.

有没有更好的办法?

发布问题和答案,因为我没有在网上找到其他任何记录

Mar*_*ich 39

一种简单的方法是将GenerateDocumentationFile属性设置为true.VS UI要设置路径,如果路径设置,MSBuild目标将此属性设置为true,如果属性为true,则设置默认路径GenerateDocumentationFile.所以你可以将它添加到你的csproj文件中:

<PropertyGroup>
  <GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

如果要将所有项目设置为true以共享它,Directory.Build.props请使用以下内容创建在解决方案目录中命名的文件,并将其自动导入到以下目录层次结构中的任何项目中:

<Project>
  <PropertyGroup>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
  </PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)

  • 是的,“$(AssemblyName)”在首次导入后的任何地方都可以。我使用类似以下内容并且它有效:`&lt;DocumentationFile&gt;$(OutputPath)\$(AssemblyName).xml&lt;/DocumentationFile&gt;`并且它有效。 (4认同)
  • 不幸的是,这不适用于旧的 .NET 框架项目 (2认同)

Ian*_*cer 5

解决此问题的一种方法是在每个CSPROJ文件中包括以下内容:

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

更好的方法是链接到共享配置文件:

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

...然后将在共享的配置文件上面行,你也可以设置所有其他解决方案范围的csproj设置,如ProductCompanyCopyright,...