VSIX - 如何在包中包含 XML 文档文件?

VSIX - How to include XML documentation files in package?

我发现以下文章很好地描述了如何将项目引用的 PDB 文件包含在 VSIX 包中:http://www.cazzulino.com/include-pdbs-in-vsix.html

现在我想做同样的事情,但是对于由项目引用生成的文档 XML 文件。我看到 XML 文件已复制到 VSIX 项目的输出目录,但如何确保它们也被添加到 .VSIX 文件?

您可以通过在您的项目文件中使用 VSIXSourceItem 或从单独的导入项目中使用它来添加您想要的任何文件:

...
<!--You also can invoke this target before GetVsixSourceItems-->
<Target Name="ForceIncludeItems" AfterTargets="GetVsixSourceItems"> 
  <ItemGroup>
    <VSIXSourceItem Include="Path_to_your_xml_file" />
  </ItemGroup>
</Target>

你也可以指定wildcards和函数到select你想要的特殊文件:

...
<VSIXSourceItem Include="*.xml" Condition="$([System.String]::new('%FileName)').StartsWith('My_start_with_pattern'))"/>

更简单但不太灵活的方法是将 IncludeDocFilesInVSIXContainer 设置为 true:

...
<IncludeDocFilesInVSIXContainer>true</IncludeDocFilesInVSIXContainer>

通过这种方式,目标将包含所有作为@DocFileItem 包含的项目(据我所知,默认情况下它只包含 vsix 项目本身的 xml 文件)。

因此,要添加所有 xml 文件(不包括被 vsix 构建包抑制的文件),您需要手动添加它们:

...
<IncludeDocFilesInVSIXContainer>true</IncludeDocFilesInVSIXContainer>

...
<Target Name="AppendNonSuppressXml" AfterTargets="GetVsixSourceItems">
    <ItemGroup>
      <SuppressXml Include="@(SuppressFromVsix->'%(FileName)')" /> <!-- store all suppressed assemblies names to avoid copying their xml files-->
    </ItemGroup>
    <PropertyGroup>
      <SuppressAsString>$([System.String]::Join(';', @(SuppressXml))</SuppressAsString> <!-- use to emulate Collections.Contains(item)-->
    </PropertyGroup>
    <ItemGroup>
      <!-- assume that xml files will be received from ReferenceCopyLocalPaths, you can use another source -->
       <VSIXSourceItem 
        Include="@(ReferenceCopyLocalPaths)"
        Condition="$(IncludeDocFilesInVSIXContainer) And '%(ReferenceCopyLocalPaths.Extension)' =='.xml' 
         And !($([System.String]::new($(SuppressAsString)).Contains('%(ReferenceCopyLocalPaths.FileName)')))" />
    </ItemGroup>
</Target>

回答我自己的问题:

显然还有一个 "DocumentationProjectOutputGroup" 输出组。然后可以通过以下方式将此输出组添加到所有项目引用中:

<PropertyGroup>
    <DefaultIncludeOutputGroupsInVSIX>
        BuiltProjectOutputGroup;
        DebugSymbolsProjectOutputGroup;
        GetCopyToOutputDirectoryItems;
        SatelliteDllsProjectOutputGroup;
        BuiltProjectOutputGroupDependencies;
        DocumentationProjectOutputGroup;
        SatelliteDllsProjectOutputGroupDependencies
    </DefaultIncludeOutputGroupsInVSIX>
</PropertyGroup>

<ItemDefinitionGroup>
    <ProjectReference>
        <IncludeOutputGroupsInVSIX>$(DefaultIncludeOutputGroupsInVSIX)</IncludeOutputGroupsInVSIX>
    </ProjectReference>
</ItemDefinitionGroup>